import static java.util.Arrays.asList; | import static java.util.Arrays.asList; | ||||
import static java.util.Collections.emptyList; | import static java.util.Collections.emptyList; | ||||
import static java.util.Collections.singletonList; | import static java.util.Collections.singletonList; | ||||
import static org.apache.commons.lang.StringUtils.defaultString; | |||||
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; | import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; | ||||
import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; | import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime; | ||||
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime; | import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime; | ||||
import static org.sonar.core.util.stream.MoreCollectors.toList; | import static org.sonar.core.util.stream.MoreCollectors.toList; | ||||
import static org.sonar.db.Pagination.forPage; | import static org.sonar.db.Pagination.forPage; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_QUERY; | |||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_ONLY_CURRENTS; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_ONLY_CURRENTS; | ||||
new Change("6.1", "field \"logs\" is deprecated and its value is always false"), | new Change("6.1", "field \"logs\" is deprecated and its value is always false"), | ||||
new Change("6.6", "fields \"branch\" and \"branchType\" added"), | new Change("6.6", "fields \"branch\" and \"branchType\" added"), | ||||
new Change("7.1", "field \"pullRequest\" added"), | new Change("7.1", "field \"pullRequest\" added"), | ||||
new Change("7.6", String.format("The use of module keys in parameters '%s' and '%s' is deprecated", TEXT_QUERY, PARAM_COMPONENT_QUERY))) | |||||
new Change("7.6", format("The use of module keys in parameters '%s' is deprecated", TEXT_QUERY))) | |||||
.setSince("5.2"); | .setSince("5.2"); | ||||
action.createParam(PARAM_COMPONENT_ID) | action.createParam(PARAM_COMPONENT_ID) | ||||
.setDescription("Id of the component (project) to filter on") | .setDescription("Id of the component (project) to filter on") | ||||
.setExampleValue(Uuids.UUID_EXAMPLE_03); | .setExampleValue(Uuids.UUID_EXAMPLE_03); | ||||
action.createParam(PARAM_COMPONENT_QUERY) | |||||
.setDescription(format("Limit search to: <ul>" + | |||||
"<li>component names that contain the supplied string</li>" + | |||||
"<li>component keys that are exactly the same as the supplied string</li>" + | |||||
"</ul>" + | |||||
"Must not be set together with %s.<br />" + | |||||
"Deprecated and replaced by '%s'", PARAM_COMPONENT_ID, TEXT_QUERY)) | |||||
.setExampleValue("Apache") | |||||
.setDeprecatedSince("5.5"); | |||||
action.createParam(TEXT_QUERY) | action.createParam(TEXT_QUERY) | ||||
.setDescription(format("Limit search to: <ul>" + | .setDescription(format("Limit search to: <ul>" + | ||||
"<li>component names that contain the supplied string</li>" + | "<li>component names that contain the supplied string</li>" + | ||||
action.createParam(PARAM_MAX_EXECUTED_AT) | action.createParam(PARAM_MAX_EXECUTED_AT) | ||||
.setDescription("Maximum date of end of task processing (inclusive)") | .setDescription("Maximum date of end of task processing (inclusive)") | ||||
.setExampleValue("2017-10-19T13:00:00+0200"); | .setExampleValue("2017-10-19T13:00:00+0200"); | ||||
action.createParam(Param.PAGE) | |||||
.setDescription("Deprecated parameter") | |||||
.setDeprecatedSince("5.5") | |||||
.setDeprecatedKey("pageIndex", "5.4"); | |||||
action.createPageSize(100, MAX_PAGE_SIZE); | action.createPageSize(100, MAX_PAGE_SIZE); | ||||
} | } | ||||
private static Request toSearchWsRequest(org.sonar.api.server.ws.Request request) { | private static Request toSearchWsRequest(org.sonar.api.server.ws.Request request) { | ||||
Request activityWsRequest = new Request() | Request activityWsRequest = new Request() | ||||
.setComponentId(request.param(PARAM_COMPONENT_ID)) | .setComponentId(request.param(PARAM_COMPONENT_ID)) | ||||
.setQ(defaultString(request.param(TEXT_QUERY), request.param(PARAM_COMPONENT_QUERY))) | |||||
.setQ(request.param(TEXT_QUERY)) | |||||
.setStatus(request.paramAsStrings(PARAM_STATUS)) | .setStatus(request.paramAsStrings(PARAM_STATUS)) | ||||
.setType(request.param(PARAM_TYPE)) | .setType(request.param(PARAM_TYPE)) | ||||
.setMinSubmittedAt(request.param(PARAM_MIN_SUBMITTED_AT)) | .setMinSubmittedAt(request.param(PARAM_MIN_SUBMITTED_AT)) | ||||
.setPs(String.valueOf(request.mandatoryParamAsInt(Param.PAGE_SIZE))); | .setPs(String.valueOf(request.mandatoryParamAsInt(Param.PAGE_SIZE))); | ||||
checkRequest(activityWsRequest.getComponentId() == null || activityWsRequest.getQ() == null, "%s and %s must not be set at the same time", | checkRequest(activityWsRequest.getComponentId() == null || activityWsRequest.getQ() == null, "%s and %s must not be set at the same time", | ||||
PARAM_COMPONENT_ID, PARAM_COMPONENT_QUERY); | |||||
PARAM_COMPONENT_ID, TEXT_QUERY); | |||||
return activityWsRequest; | return activityWsRequest; | ||||
} | } | ||||
private List<String> status; | private List<String> status; | ||||
private String type; | private String type; | ||||
Request() { | |||||
// Nothing to do | |||||
} | |||||
/** | /** | ||||
* Example value: "AU-TpxcA-iU5OvuD2FL0" | * Example value: "AU-TpxcA-iU5OvuD2FL0" | ||||
*/ | */ | ||||
private Request setComponentId(String componentId) { | |||||
private Request setComponentId(@Nullable String componentId) { | |||||
this.componentId = componentId; | this.componentId = componentId; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private String getComponentId() { | private String getComponentId() { | ||||
return componentId; | return componentId; | ||||
} | } | ||||
/** | /** | ||||
* Example value: "2017-10-19T13:00:00+0200" | * Example value: "2017-10-19T13:00:00+0200" | ||||
*/ | */ | ||||
private Request setMaxExecutedAt(String maxExecutedAt) { | |||||
private Request setMaxExecutedAt(@Nullable String maxExecutedAt) { | |||||
this.maxExecutedAt = maxExecutedAt; | this.maxExecutedAt = maxExecutedAt; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private String getMaxExecutedAt() { | private String getMaxExecutedAt() { | ||||
return maxExecutedAt; | return maxExecutedAt; | ||||
} | } | ||||
/** | /** | ||||
* Example value: "2017-10-19T13:00:00+0200" | * Example value: "2017-10-19T13:00:00+0200" | ||||
*/ | */ | ||||
private Request setMinSubmittedAt(String minSubmittedAt) { | |||||
private Request setMinSubmittedAt(@Nullable String minSubmittedAt) { | |||||
this.minSubmittedAt = minSubmittedAt; | this.minSubmittedAt = minSubmittedAt; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private String getMinSubmittedAt() { | private String getMinSubmittedAt() { | ||||
return minSubmittedAt; | return minSubmittedAt; | ||||
} | } | ||||
/** | /** | ||||
* Example value: "Apache" | * Example value: "Apache" | ||||
*/ | */ | ||||
private Request setQ(String q) { | |||||
private Request setQ(@Nullable String q) { | |||||
this.q = q; | this.q = q; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private String getQ() { | private String getQ() { | ||||
return q; | return q; | ||||
} | } | ||||
* <li>"IN_PROGRESS"</li> | * <li>"IN_PROGRESS"</li> | ||||
* </ul> | * </ul> | ||||
*/ | */ | ||||
private Request setStatus(List<String> status) { | |||||
private Request setStatus(@Nullable List<String> status) { | |||||
this.status = status; | this.status = status; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private List<String> getStatus() { | private List<String> getStatus() { | ||||
return status; | return status; | ||||
} | } | ||||
* <li>"REPORT"</li> | * <li>"REPORT"</li> | ||||
* </ul> | * </ul> | ||||
*/ | */ | ||||
private Request setType(String type) { | |||||
private Request setType(@Nullable String type) { | |||||
this.type = type; | this.type = type; | ||||
return this; | return this; | ||||
} | } | ||||
@CheckForNull | |||||
private String getType() { | private String getType() { | ||||
return type; | return type; | ||||
} | } |
public static final String PARAM_COMPONENT_ID = "componentId"; | public static final String PARAM_COMPONENT_ID = "componentId"; | ||||
public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey"; | public static final String DEPRECATED_PARAM_COMPONENT_KEY = "componentKey"; | ||||
public static final String PARAM_COMPONENT = "component"; | public static final String PARAM_COMPONENT = "component"; | ||||
public static final String PARAM_COMPONENT_QUERY = "componentQuery"; | |||||
public static final String PARAM_TYPE = "type"; | public static final String PARAM_TYPE = "type"; | ||||
public static final String PARAM_STATUS = "status"; | public static final String PARAM_STATUS = "status"; | ||||
public static final String PARAM_ONLY_CURRENTS = "onlyCurrents"; | public static final String PARAM_ONLY_CURRENTS = "onlyCurrents"; |
@Override | @Override | ||||
protected void configureModule() { | protected void configureModule() { | ||||
add( | add( | ||||
ResourcesWs.class, | |||||
ComponentsWs.class, | ComponentsWs.class, | ||||
// actions | // actions | ||||
AppAction.class, | AppAction.class, |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.component.ws; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.server.ws.RemovedWebServiceHandler; | |||||
public class ResourcesWs implements WebService { | |||||
@Override | |||||
public void define(Context context) { | |||||
NewController controller = context.createController("api/resources") | |||||
.setDescription("Removed since 6.3, please use api/components and api/measures instead") | |||||
.setSince("2.10"); | |||||
defineIndexAction(controller); | |||||
controller.done(); | |||||
} | |||||
private static void defineIndexAction(NewController controller) { | |||||
controller.createAction("index") | |||||
.setDescription("The web service is removed and you're invited to use the alternatives: " + | |||||
"<ul>" + | |||||
"<li>if you need one component without measures: api/components/show</li>" + | |||||
"<li>if you need one component with measures: api/measures/component</li>" + | |||||
"<li>if you need several components without measures: api/components/tree</li>" + | |||||
"<li>if you need several components with measures: api/measures/component_tree</li>" + | |||||
"</ul>") | |||||
.setSince("2.10") | |||||
.setDeprecatedSince("5.4") | |||||
.setHandler(RemovedWebServiceHandler.INSTANCE) | |||||
.setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); | |||||
} | |||||
} |
import static org.sonar.core.util.stream.MoreCollectors.toList; | import static org.sonar.core.util.stream.MoreCollectors.toList; | ||||
import static org.sonar.core.util.stream.MoreCollectors.toSet; | import static org.sonar.core.util.stream.MoreCollectors.toSet; | ||||
import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; | import static org.sonar.core.util.stream.MoreCollectors.uniqueIndex; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_IN_LAST; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_IN_LAST; | ||||
boolean effectiveOnComponentOnly = false; | boolean effectiveOnComponentOnly = false; | ||||
checkArgument(atMostOneNonNullElement(components, componentUuids, componentKeys, componentRootUuids, componentRoots), | checkArgument(atMostOneNonNullElement(components, componentUuids, componentKeys, componentRootUuids, componentRoots), | ||||
"At most one of the following parameters can be provided: %s, %s, %s, %s, %s", | |||||
PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS, PARAM_COMPONENTS, PARAM_COMPONENT_ROOTS, PARAM_COMPONENT_UUIDS); | |||||
"At most one of the following parameters can be provided: %s and %s", PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS); | |||||
if (componentRootUuids != null) { | if (componentRootUuids != null) { | ||||
allComponents.addAll(getComponentsFromUuids(session, componentRootUuids)); | allComponents.addAll(getComponentsFromUuids(session, componentRootUuids)); |
import com.google.common.base.Strings; | import com.google.common.base.Strings; | ||||
import com.google.common.io.Resources; | import com.google.common.io.Resources; | ||||
import java.util.Date; | import java.util.Date; | ||||
import java.util.Optional; | |||||
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.apache.commons.lang.BooleanUtils; | |||||
import org.sonar.api.rules.RuleType; | import org.sonar.api.rules.RuleType; | ||||
import org.sonar.api.server.ws.Change; | import org.sonar.api.server.ws.Change; | ||||
import org.sonar.api.server.ws.Request; | import org.sonar.api.server.ws.Request; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUE; | ||||
public class AssignAction implements IssuesWsAction { | public class AssignAction implements IssuesWsAction { | ||||
private static final String DEPRECATED_PARAM_ME = "me"; | |||||
private static final String ASSIGN_TO_ME_VALUE = "_me"; | private static final String ASSIGN_TO_ME_VALUE = "_me"; | ||||
private final System2 system2; | private final System2 system2; | ||||
action.createParam(PARAM_ASSIGNEE) | action.createParam(PARAM_ASSIGNEE) | ||||
.setDescription("Login of the assignee. When not set, it will unassign the issue. Use '%s' to assign to current user", ASSIGN_TO_ME_VALUE) | .setDescription("Login of the assignee. When not set, it will unassign the issue. Use '%s' to assign to current user", ASSIGN_TO_ME_VALUE) | ||||
.setExampleValue("admin"); | .setExampleValue("admin"); | ||||
action.createParam(DEPRECATED_PARAM_ME) | |||||
.setDescription("(deprecated) Assign the issue to the logged-in user. Replaced by the parameter assignee=_me") | |||||
.setDeprecatedSince("5.2") | |||||
.setBooleanPossibleValues(); | |||||
} | } | ||||
@Override | @Override | ||||
try (DbSession dbSession = dbClient.openSession(false)) { | try (DbSession dbSession = dbClient.openSession(false)) { | ||||
IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey); | IssueDto issueDto = issueFinder.getByKey(dbSession, issueKey); | ||||
DefaultIssue issue = issueDto.toDefaultIssue(); | DefaultIssue issue = issueDto.toDefaultIssue(); | ||||
checkArgument(issue.type() != RuleType.SECURITY_HOTSPOT,"It is not allowed to assign a security hotspot"); | |||||
checkArgument(issue.type() != RuleType.SECURITY_HOTSPOT, "Assigning security hotspots is not allowed"); | |||||
UserDto user = getUser(dbSession, login); | UserDto user = getUser(dbSession, login); | ||||
if (user != null) { | if (user != null) { | ||||
checkMembership(dbSession, issueDto, user); | checkMembership(dbSession, issueDto, user); | ||||
@CheckForNull | @CheckForNull | ||||
private String getAssignee(Request request) { | private String getAssignee(Request request) { | ||||
String assignee = emptyToNull(request.param(PARAM_ASSIGNEE)); | String assignee = emptyToNull(request.param(PARAM_ASSIGNEE)); | ||||
if (ASSIGN_TO_ME_VALUE.equals(assignee) || BooleanUtils.isTrue(request.paramAsBoolean(DEPRECATED_PARAM_ME))) { | |||||
return userSession.getLogin(); | |||||
} | |||||
return assignee; | |||||
return ASSIGN_TO_ME_VALUE.equals(assignee) ? userSession.getLogin() : assignee; | |||||
} | } | ||||
@CheckForNull | @CheckForNull | ||||
private void checkMembership(DbSession dbSession, IssueDto issueDto, UserDto user) { | private void checkMembership(DbSession dbSession, IssueDto issueDto, UserDto user) { | ||||
String projectUuid = requireNonNull(issueDto.getProjectUuid()); | String projectUuid = requireNonNull(issueDto.getProjectUuid()); | ||||
ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null)) | |||||
ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, projectUuid) | |||||
.orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid))); | .orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid))); | ||||
OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid()) | OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid()) | ||||
.orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid()))); | .orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid()))); |
import org.sonar.server.issue.AddTagsAction; | import org.sonar.server.issue.AddTagsAction; | ||||
import org.sonar.server.issue.AssignAction; | import org.sonar.server.issue.AssignAction; | ||||
import org.sonar.server.issue.IssueChangePostProcessor; | import org.sonar.server.issue.IssueChangePostProcessor; | ||||
import org.sonar.server.issue.WebIssueStorage; | |||||
import org.sonar.server.issue.RemoveTagsAction; | import org.sonar.server.issue.RemoveTagsAction; | ||||
import org.sonar.server.issue.WebIssueStorage; | |||||
import org.sonar.server.issue.notification.IssueChangeNotification; | import org.sonar.server.issue.notification.IssueChangeNotification; | ||||
import org.sonar.server.notification.NotificationManager; | import org.sonar.server.notification.NotificationManager; | ||||
import org.sonar.server.user.UserSession; | import org.sonar.server.user.UserSession; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMMENT; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMMENT; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DO_TRANSITION; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DO_TRANSITION; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ISSUES; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PLAN; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REMOVE_TAGS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REMOVE_TAGS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEND_NOTIFICATIONS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SEND_NOTIFICATIONS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_SEVERITY; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SET_SEVERITY; | ||||
.setPossibleValues(RuleType.names()) | .setPossibleValues(RuleType.names()) | ||||
.setSince("5.5") | .setSince("5.5") | ||||
.setDeprecatedKey("set_type.type", "6.2"); | .setDeprecatedKey("set_type.type", "6.2"); | ||||
action.createParam(PARAM_PLAN) | |||||
.setDescription("In 5.5, action plans are dropped. Has no effect. To plan the list of issues to a specific action plan (key), or unlink all the issues from an action plan") | |||||
.setDeprecatedSince("5.5"); | |||||
action.createParam(PARAM_DO_TRANSITION) | action.createParam(PARAM_DO_TRANSITION) | ||||
.setDescription("Transition") | .setDescription("Transition") | ||||
.setExampleValue(REOPEN) | .setExampleValue(REOPEN) |
import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; | import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; | ||||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | import static org.sonar.server.ws.WsUtils.writeProtobuf; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_SEARCH; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_SEARCH; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_PARAM_ACTION_PLANS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_PARAM_AUTHORS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_PARAM_AUTHORS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_COUNT; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_COUNT; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_AUTHOR; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_AUTHOR; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_BRANCH; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_BRANCH; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_ROOT_UUIDS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AT; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AT; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECTS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECT_KEYS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PROJECT_KEYS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_REPORTERS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLUTIONS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLUTIONS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLVED; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RESOLVED; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES; | ||||
PARAM_SEVERITIES, | PARAM_SEVERITIES, | ||||
PARAM_STATUSES, | PARAM_STATUSES, | ||||
PARAM_RESOLUTIONS, | PARAM_RESOLUTIONS, | ||||
DEPRECATED_PARAM_ACTION_PLANS, | |||||
PARAM_RULES, | PARAM_RULES, | ||||
PARAM_ASSIGNEES, | PARAM_ASSIGNEES, | ||||
PARAM_REPORTERS, | |||||
DEPRECATED_PARAM_AUTHORS, | DEPRECATED_PARAM_AUTHORS, | ||||
PARAM_AUTHOR, | PARAM_AUTHOR, | ||||
PARAM_DIRECTORIES, | PARAM_DIRECTORIES, | ||||
.setHandler(this) | .setHandler(this) | ||||
.setDescription( | .setDescription( | ||||
"Search for issues.<br>" + | "Search for issues.<br>" + | ||||
"At most one of the following parameters can be provided at the same time: %s, %s, %s, %s, %s.<br>" + | |||||
"At most one of the following parameters can be provided at the same time: %s and %s.<br>" + | |||||
"Requires the 'Browse' permission on the specified project(s).", | "Requires the 'Browse' permission on the specified project(s).", | ||||
PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS, PARAM_COMPONENTS, PARAM_COMPONENT_ROOT_UUIDS, PARAM_COMPONENT_ROOTS) | |||||
PARAM_COMPONENT_KEYS, PARAM_COMPONENT_UUIDS) | |||||
.setSince("3.6") | .setSince("3.6") | ||||
.setChangelog( | .setChangelog( | ||||
new Change("7.7", format("Value '%s' in parameter '%s' is deprecated, please use '%s' instead", DEPRECATED_PARAM_AUTHORS, FACETS, PARAM_AUTHOR)), | new Change("7.7", format("Value '%s' in parameter '%s' is deprecated, please use '%s' instead", DEPRECATED_PARAM_AUTHORS, FACETS, PARAM_AUTHOR)), | ||||
private static void addComponentRelatedParams(WebService.NewAction action) { | private static void addComponentRelatedParams(WebService.NewAction action) { | ||||
action.createParam(PARAM_ON_COMPONENT_ONLY) | action.createParam(PARAM_ON_COMPONENT_ONLY) | ||||
.setDescription("Return only issues at a component's level, not on its descendants (modules, directories, files, etc). " + | .setDescription("Return only issues at a component's level, not on its descendants (modules, directories, files, etc). " + | ||||
"This parameter is only considered when componentKeys or componentUuids is set. " + | |||||
"Using the deprecated componentRoots or componentRootUuids parameters will set this parameter to false. " + | |||||
"Using the deprecated components parameter will set this parameter to true.") | |||||
"This parameter is only considered when componentKeys or componentUuids is set.") | |||||
.setBooleanPossibleValues() | .setBooleanPossibleValues() | ||||
.setDefaultValue("false"); | .setDefaultValue("false"); | ||||
"A component can be a portfolio, project, module, directory or file.") | "A component can be a portfolio, project, module, directory or file.") | ||||
.setExampleValue(KEY_PROJECT_EXAMPLE_001); | .setExampleValue(KEY_PROJECT_EXAMPLE_001); | ||||
action.createParam(PARAM_COMPONENTS) | |||||
.setDeprecatedSince("5.1") | |||||
.setDescription("If used, will have the same meaning as componentKeys AND onComponentOnly=true."); | |||||
action.createParam(PARAM_COMPONENT_UUIDS) | action.createParam(PARAM_COMPONENT_UUIDS) | ||||
.setDescription("To retrieve issues associated to a specific list of components their sub-components (comma-separated list of component IDs). " + | .setDescription("To retrieve issues associated to a specific list of components their sub-components (comma-separated list of component IDs). " + | ||||
INTERNAL_PARAMETER_DISCLAIMER + | INTERNAL_PARAMETER_DISCLAIMER + | ||||
.setDeprecatedSince("6.5") | .setDeprecatedSince("6.5") | ||||
.setExampleValue("584a89f2-8037-4f7b-b82c-8b45d2d63fb2"); | .setExampleValue("584a89f2-8037-4f7b-b82c-8b45d2d63fb2"); | ||||
action.createParam(PARAM_COMPONENT_ROOTS) | |||||
.setDeprecatedSince("5.1") | |||||
.setDescription("If used, will have the same meaning as componentKeys AND onComponentOnly=false."); | |||||
action.createParam(PARAM_COMPONENT_ROOT_UUIDS) | |||||
.setDeprecatedSince("5.1") | |||||
.setDescription("If used, will have the same meaning as componentUuids AND onComponentOnly=false."); | |||||
action.createParam(PARAM_PROJECTS) | action.createParam(PARAM_PROJECTS) | ||||
.setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project keys). " + | .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project keys). " + | ||||
INTERNAL_PARAMETER_DISCLAIMER + | INTERNAL_PARAMETER_DISCLAIMER + | ||||
.setAssigneesUuid(getLogins(dbSession, request.paramAsStrings(PARAM_ASSIGNEES))) | .setAssigneesUuid(getLogins(dbSession, request.paramAsStrings(PARAM_ASSIGNEES))) | ||||
.setAuthors(request.hasParam(PARAM_AUTHOR) ? request.multiParam(PARAM_AUTHOR) : request.paramAsStrings(DEPRECATED_PARAM_AUTHORS)) | .setAuthors(request.hasParam(PARAM_AUTHOR) ? request.multiParam(PARAM_AUTHOR) : request.paramAsStrings(DEPRECATED_PARAM_AUTHORS)) | ||||
.setComponentKeys(request.paramAsStrings(PARAM_COMPONENT_KEYS)) | .setComponentKeys(request.paramAsStrings(PARAM_COMPONENT_KEYS)) | ||||
.setComponentRootUuids(request.paramAsStrings(PARAM_COMPONENT_ROOT_UUIDS)) | |||||
.setComponentRoots(request.paramAsStrings(PARAM_COMPONENT_ROOTS)) | |||||
.setComponentUuids(request.paramAsStrings(PARAM_COMPONENT_UUIDS)) | .setComponentUuids(request.paramAsStrings(PARAM_COMPONENT_UUIDS)) | ||||
.setComponents(request.paramAsStrings(PARAM_COMPONENTS)) | |||||
.setCreatedAfter(request.param(PARAM_CREATED_AFTER)) | .setCreatedAfter(request.param(PARAM_CREATED_AFTER)) | ||||
.setCreatedAt(request.param(PARAM_CREATED_AT)) | .setCreatedAt(request.param(PARAM_CREATED_AT)) | ||||
.setCreatedBefore(request.param(PARAM_CREATED_BEFORE)) | .setCreatedBefore(request.param(PARAM_CREATED_BEFORE)) |
import org.sonar.server.qualityprofile.QProfileTreeImpl; | import org.sonar.server.qualityprofile.QProfileTreeImpl; | ||||
import org.sonar.server.qualityprofile.RuleActivator; | import org.sonar.server.qualityprofile.RuleActivator; | ||||
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; | import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; | ||||
import org.sonar.server.qualityprofile.ws.ProfilesWs; | |||||
import org.sonar.server.qualityprofile.ws.QProfilesWsModule; | import org.sonar.server.qualityprofile.ws.QProfilesWsModule; | ||||
import org.sonar.server.root.ws.RootWsModule; | import org.sonar.server.root.ws.RootWsModule; | ||||
import org.sonar.server.rule.CommonRuleDefinitionsImpl; | import org.sonar.server.rule.CommonRuleDefinitionsImpl; | ||||
import org.sonar.server.telemetry.TelemetryClient; | import org.sonar.server.telemetry.TelemetryClient; | ||||
import org.sonar.server.telemetry.TelemetryDaemon; | import org.sonar.server.telemetry.TelemetryDaemon; | ||||
import org.sonar.server.telemetry.TelemetryDataLoader; | import org.sonar.server.telemetry.TelemetryDataLoader; | ||||
import org.sonar.server.test.ws.TestsWs; | |||||
import org.sonar.server.text.MacroInterpreter; | import org.sonar.server.text.MacroInterpreter; | ||||
import org.sonar.server.ui.DeprecatedViews; | import org.sonar.server.ui.DeprecatedViews; | ||||
import org.sonar.server.ui.PageDecorations; | import org.sonar.server.ui.PageDecorations; | ||||
XMLProfileSerializer.class, | XMLProfileSerializer.class, | ||||
AnnotationProfileParser.class, | AnnotationProfileParser.class, | ||||
QProfileComparison.class, | QProfileComparison.class, | ||||
ProfilesWs.class, | |||||
QProfileTreeImpl.class, | QProfileTreeImpl.class, | ||||
QProfileRulesImpl.class, | QProfileRulesImpl.class, | ||||
RuleActivator.class, | RuleActivator.class, | ||||
NotificationWsModule.class, | NotificationWsModule.class, | ||||
EmailsWsModule.class, | EmailsWsModule.class, | ||||
// Tests | |||||
TestsWs.class, | |||||
// Settings | // Settings | ||||
PersistentSettings.class, | PersistentSettings.class, | ||||
PropertiesWs.class, | PropertiesWs.class, |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.qualityprofile.ws; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.server.ws.RemovedWebServiceHandler; | |||||
/** | |||||
* List of quality profiles WS implemented in Rails. | |||||
* New WS on quality profiles MUST be declared in {@link org.sonar.server.qualityprofile.ws.QProfilesWs} | |||||
*/ | |||||
public class ProfilesWs implements WebService { | |||||
public static final String API_ENDPOINT = "api/profiles"; | |||||
@Override | |||||
public void define(Context context) { | |||||
NewController controller = context.createController(API_ENDPOINT) | |||||
.setDescription("Removed since 6.3, please use api/qualityprofiles instead") | |||||
.setSince("4.4"); | |||||
defineListAction(controller); | |||||
defineIndexAction(controller); | |||||
controller.done(); | |||||
} | |||||
private static void defineIndexAction(NewController controller) { | |||||
controller.createAction("index") | |||||
.setDescription("Get a profile.<br/>" + | |||||
"The web service is removed and you're invited to use api/qualityprofiles/search instead") | |||||
.setSince("3.3") | |||||
.setDeprecatedSince("5.2") | |||||
.setHandler(RemovedWebServiceHandler.INSTANCE) | |||||
.setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); | |||||
} | |||||
private static void defineListAction(NewController controller) { | |||||
controller.createAction("list") | |||||
.setDescription("Get a list of profiles.<br/>" + | |||||
"The web service is removed and you're invited to use api/qualityprofiles/search instead") | |||||
.setSince("3.3") | |||||
.setDeprecatedSince("5.2") | |||||
.setHandler(RemovedWebServiceHandler.INSTANCE) | |||||
.setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()); | |||||
} | |||||
} |
.setDescription("Key of the custom rule") | .setDescription("Key of the custom rule") | ||||
.setExampleValue("Todo_should_not_be_used"); | .setExampleValue("Todo_should_not_be_used"); | ||||
action | |||||
.createParam("manual_key") | |||||
.setDescription("Manual rules are no more supported. This parameter is ignored") | |||||
.setExampleValue("Error_handling") | |||||
.setDeprecatedSince("5.5"); | |||||
action | action | ||||
.createParam(PARAM_TEMPLATE_KEY) | .createParam(PARAM_TEMPLATE_KEY) | ||||
.setDescription("Key of the template rule in order to create a custom rule (mandatory for custom rule)") | .setDescription("Key of the template rule in order to create a custom rule (mandatory for custom rule)") |
import static java.lang.String.format; | import static java.lang.String.format; | ||||
import static java.util.Collections.singletonList; | import static java.util.Collections.singletonList; | ||||
import static java.util.Optional.ofNullable; | import static java.util.Optional.ofNullable; | ||||
import static org.apache.commons.lang.StringUtils.defaultIfEmpty; | |||||
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; | import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; | ||||
import static org.sonar.server.rule.ws.CreateAction.KEY_MAXIMUM_LENGTH; | import static org.sonar.server.rule.ws.CreateAction.KEY_MAXIMUM_LENGTH; | ||||
import static org.sonar.server.rule.ws.CreateAction.NAME_MAXIMUM_LENGTH; | import static org.sonar.server.rule.ws.CreateAction.NAME_MAXIMUM_LENGTH; | ||||
public static final String PARAM_TAGS = "tags"; | public static final String PARAM_TAGS = "tags"; | ||||
public static final String PARAM_MARKDOWN_NOTE = "markdown_note"; | public static final String PARAM_MARKDOWN_NOTE = "markdown_note"; | ||||
public static final String PARAM_REMEDIATION_FN_TYPE = "remediation_fn_type"; | public static final String PARAM_REMEDIATION_FN_TYPE = "remediation_fn_type"; | ||||
public static final String DEPRECATED_PARAM_REMEDIATION_FN_TYPE = "debt_remediation_fn_type"; | |||||
public static final String PARAM_REMEDIATION_FN_BASE_EFFORT = "remediation_fn_base_effort"; | public static final String PARAM_REMEDIATION_FN_BASE_EFFORT = "remediation_fn_base_effort"; | ||||
public static final String DEPRECATED_PARAM_REMEDIATION_FN_OFFSET = "debt_remediation_fn_offset"; | |||||
public static final String PARAM_REMEDIATION_FN_GAP_MULTIPLIER = "remediation_fy_gap_multiplier"; | public static final String PARAM_REMEDIATION_FN_GAP_MULTIPLIER = "remediation_fy_gap_multiplier"; | ||||
public static final String DEPRECATED_PARAM_REMEDIATION_FN_COEFF = "debt_remediation_fy_coeff"; | |||||
public static final String PARAM_NAME = "name"; | public static final String PARAM_NAME = "name"; | ||||
public static final String PARAM_DESCRIPTION = "markdown_description"; | public static final String PARAM_DESCRIPTION = "markdown_description"; | ||||
public static final String PARAM_SEVERITY = "severity"; | public static final String PARAM_SEVERITY = "severity"; | ||||
.setPossibleValues(DebtRemediationFunction.Type.values()) | .setPossibleValues(DebtRemediationFunction.Type.values()) | ||||
.setSince("5.5"); | .setSince("5.5"); | ||||
action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_TYPE) | |||||
.setDeprecatedSince("5.5") | |||||
.setPossibleValues(DebtRemediationFunction.Type.values()); | |||||
action.createParam(PARAM_REMEDIATION_FN_BASE_EFFORT) | action.createParam(PARAM_REMEDIATION_FN_BASE_EFFORT) | ||||
.setDescription("Base effort of the remediation function of the rule") | .setDescription("Base effort of the remediation function of the rule") | ||||
.setExampleValue("1d") | .setExampleValue("1d") | ||||
.setSince("5.5"); | .setSince("5.5"); | ||||
action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET) | |||||
.setDeprecatedSince("5.5"); | |||||
action.createParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER) | action.createParam(PARAM_REMEDIATION_FN_GAP_MULTIPLIER) | ||||
.setDescription("Gap multiplier of the remediation function of the rule") | .setDescription("Gap multiplier of the remediation function of the rule") | ||||
.setExampleValue("3min") | .setExampleValue("3min") | ||||
.setSince("5.5"); | .setSince("5.5"); | ||||
action.createParam(DEPRECATED_PARAM_REMEDIATION_FN_COEFF) | |||||
.setDeprecatedSince("5.5"); | |||||
action | action | ||||
.createParam(PARAM_NAME) | .createParam(PARAM_NAME) | ||||
.setMaximumLength(NAME_MAXIMUM_LENGTH) | .setMaximumLength(NAME_MAXIMUM_LENGTH) | ||||
} | } | ||||
private static void readDebt(Request request, RuleUpdate update) { | private static void readDebt(Request request, RuleUpdate update) { | ||||
String value = defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_TYPE), request.param(DEPRECATED_PARAM_REMEDIATION_FN_TYPE)); | |||||
String value = request.param(PARAM_REMEDIATION_FN_TYPE); | |||||
if (value != null) { | if (value != null) { | ||||
if (StringUtils.isBlank(value)) { | if (StringUtils.isBlank(value)) { | ||||
update.setDebtRemediationFunction(null); | update.setDebtRemediationFunction(null); | ||||
} else { | } else { | ||||
DebtRemediationFunction fn = new DefaultDebtRemediationFunction( | DebtRemediationFunction fn = new DefaultDebtRemediationFunction( | ||||
DebtRemediationFunction.Type.valueOf(value), | DebtRemediationFunction.Type.valueOf(value), | ||||
defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), request.param(DEPRECATED_PARAM_REMEDIATION_FN_COEFF)), | |||||
defaultIfEmpty(request.param(PARAM_REMEDIATION_FN_BASE_EFFORT), request.param(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET))); | |||||
request.param(PARAM_REMEDIATION_FN_GAP_MULTIPLIER), | |||||
request.param(PARAM_REMEDIATION_FN_BASE_EFFORT)); | |||||
update.setDebtRemediationFunction(fn); | update.setDebtRemediationFunction(fn); | ||||
} | } | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.test.ws; | |||||
import org.sonar.api.server.ws.Change; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.server.ws.RemovedWebServiceHandler; | |||||
public class TestsWs implements WebService { | |||||
@Override | |||||
public void define(Context context) { | |||||
NewController controller = context.createController("api/tests") | |||||
.setSince("4.4") | |||||
.setDescription("Removed in 7.6"); | |||||
controller.createAction("covered_files") | |||||
.setDescription("This web API is no longer supported") | |||||
.setSince("4.4") | |||||
.setDeprecatedSince("5.6") | |||||
.setChangelog(new Change("7.6", "This action has been removed")) | |||||
.setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()) | |||||
.setHandler(RemovedWebServiceHandler.INSTANCE); | |||||
controller | |||||
.createAction("list") | |||||
.setDescription("This web API is no longer supported") | |||||
.setSince("5.2") | |||||
.setDeprecatedSince("5.6") | |||||
.setChangelog(new Change("7.6", "This action has been removed")) | |||||
.setResponseExample(RemovedWebServiceHandler.INSTANCE.getResponseExample()) | |||||
.setHandler(RemovedWebServiceHandler.INSTANCE); | |||||
controller.done(); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
package org.sonar.server.test.ws; | |||||
import javax.annotation.ParametersAreNonnullByDefault; |
package org.sonar.server.user.ws; | package org.sonar.server.user.ws; | ||||
import com.google.common.collect.Multimap; | import com.google.common.collect.Multimap; | ||||
import java.util.ArrayList; | |||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
import java.util.function.Function; | |||||
import javax.annotation.CheckForNull; | import javax.annotation.CheckForNull; | ||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.sonar.api.server.ws.Change; | import org.sonar.api.server.ws.Change; | ||||
import static com.google.common.base.Preconditions.checkArgument; | import static com.google.common.base.Preconditions.checkArgument; | ||||
import static com.google.common.base.Strings.emptyToNull; | import static com.google.common.base.Strings.emptyToNull; | ||||
import static java.util.Optional.ofNullable; | import static java.util.Optional.ofNullable; | ||||
import static org.sonar.api.server.ws.WebService.Param.FIELDS; | |||||
import static org.sonar.api.server.ws.WebService.Param.PAGE; | import static org.sonar.api.server.ws.WebService.Param.PAGE; | ||||
import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; | import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE; | ||||
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; | import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; | ||||
import static org.sonar.api.utils.Paging.forPageIndex; | import static org.sonar.api.utils.Paging.forPageIndex; | ||||
import static org.sonar.core.util.stream.MoreCollectors.toList; | import static org.sonar.core.util.stream.MoreCollectors.toList; | ||||
import static org.sonar.server.es.SearchOptions.MAX_LIMIT; | import static org.sonar.server.es.SearchOptions.MAX_LIMIT; | ||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_ACTIVE; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_AVATAR; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EMAIL; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EXTERNAL_IDENTITY; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_EXTERNAL_PROVIDER; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_GROUPS; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_LOCAL; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_NAME; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_SCM_ACCOUNTS; | |||||
import static org.sonar.server.user.ws.UserJsonWriter.FIELD_TOKENS_COUNT; | |||||
import static org.sonar.server.ws.WsUtils.writeProtobuf; | import static org.sonar.server.ws.WsUtils.writeProtobuf; | ||||
import static org.sonarqube.ws.Users.SearchWsResponse.Groups; | import static org.sonarqube.ws.Users.SearchWsResponse.Groups; | ||||
import static org.sonarqube.ws.Users.SearchWsResponse.ScmAccounts; | import static org.sonarqube.ws.Users.SearchWsResponse.ScmAccounts; | ||||
.setHandler(this) | .setHandler(this) | ||||
.setResponseExample(getClass().getResource("search-example.json")); | .setResponseExample(getClass().getResource("search-example.json")); | ||||
action.createFieldsParam(UserJsonWriter.FIELDS) | |||||
.setDeprecatedSince("5.4"); | |||||
action.addPagingParams(50, MAX_LIMIT); | action.addPagingParams(50, MAX_LIMIT); | ||||
action.createParam(TEXT_QUERY) | action.createParam(TEXT_QUERY) | ||||
private Users.SearchWsResponse doHandle(SearchRequest request) { | private Users.SearchWsResponse doHandle(SearchRequest request) { | ||||
SearchOptions options = new SearchOptions().setPage(request.getPage(), request.getPageSize()); | SearchOptions options = new SearchOptions().setPage(request.getPage(), request.getPageSize()); | ||||
List<String> fields = request.getPossibleFields(); | |||||
SearchResult<UserDoc> result = userIndex.search(UserQuery.builder().setTextQuery(request.getQuery()).build(), options); | SearchResult<UserDoc> result = userIndex.search(UserQuery.builder().setTextQuery(request.getQuery()).build(), options); | ||||
try (DbSession dbSession = dbClient.openSession(false)) { | try (DbSession dbSession = dbClient.openSession(false)) { | ||||
List<String> logins = result.getDocs().stream().map(UserDoc::login).collect(toList()); | List<String> logins = result.getDocs().stream().map(UserDoc::login).collect(toList()); | ||||
List<UserDto> users = dbClient.userDao().selectByOrderedLogins(dbSession, logins); | List<UserDto> users = dbClient.userDao().selectByOrderedLogins(dbSession, logins); | ||||
Map<String, Integer> tokenCountsByLogin = dbClient.userTokenDao().countTokensByUsers(dbSession, users); | Map<String, Integer> tokenCountsByLogin = dbClient.userTokenDao().countTokensByUsers(dbSession, users); | ||||
Paging paging = forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal((int) result.getTotal()); | Paging paging = forPageIndex(request.getPage()).withPageSize(request.getPageSize()).andTotal((int) result.getTotal()); | ||||
return buildResponse(users, groupsByLogin, tokenCountsByLogin, fields, paging); | |||||
return buildResponse(users, groupsByLogin, tokenCountsByLogin, paging); | |||||
} | } | ||||
} | } | ||||
private SearchWsResponse buildResponse(List<UserDto> users, Multimap<String, String> groupsByLogin, Map<String, Integer> tokenCountsByLogin, | |||||
@Nullable List<String> fields, Paging paging) { | |||||
private SearchWsResponse buildResponse(List<UserDto> users, Multimap<String, String> groupsByLogin, Map<String, Integer> tokenCountsByLogin, Paging paging) { | |||||
SearchWsResponse.Builder responseBuilder = newBuilder(); | SearchWsResponse.Builder responseBuilder = newBuilder(); | ||||
users.forEach(user -> responseBuilder.addUsers(towsUser(user, firstNonNull(tokenCountsByLogin.get(user.getUuid()), 0), groupsByLogin.get(user.getLogin()), fields))); | |||||
users.forEach(user -> responseBuilder.addUsers(towsUser(user, firstNonNull(tokenCountsByLogin.get(user.getUuid()), 0), groupsByLogin.get(user.getLogin())))); | |||||
responseBuilder.getPagingBuilder() | responseBuilder.getPagingBuilder() | ||||
.setPageIndex(paging.pageIndex()) | .setPageIndex(paging.pageIndex()) | ||||
.setPageSize(paging.pageSize()) | .setPageSize(paging.pageSize()) | ||||
return responseBuilder.build(); | return responseBuilder.build(); | ||||
} | } | ||||
private User towsUser(UserDto user, @Nullable Integer tokensCount, Collection<String> groups, @Nullable Collection<String> fields) { | |||||
User.Builder userBuilder = User.newBuilder() | |||||
.setLogin(user.getLogin()); | |||||
setIfNeeded(FIELD_NAME, fields, user.getName(), userBuilder::setName); | |||||
private User towsUser(UserDto user, @Nullable Integer tokensCount, Collection<String> groups) { | |||||
User.Builder userBuilder = User.newBuilder().setLogin(user.getLogin()); | |||||
ofNullable(user.getName()).ifPresent(userBuilder::setName); | |||||
if (userSession.isLoggedIn()) { | if (userSession.isLoggedIn()) { | ||||
setIfNeeded(FIELD_AVATAR, fields, emptyToNull(user.getEmail()), u -> userBuilder.setAvatar(avatarResolver.create(user))); | |||||
setIfNeeded(FIELD_ACTIVE, fields, user.isActive(), userBuilder::setActive); | |||||
setIfNeeded(FIELD_LOCAL, fields, user.isLocal(), userBuilder::setLocal); | |||||
setIfNeeded(FIELD_EXTERNAL_PROVIDER, fields, user.getExternalIdentityProvider(), userBuilder::setExternalProvider); | |||||
setIfNeeded(isNeeded(FIELD_SCM_ACCOUNTS, fields) && !user.getScmAccountsAsList().isEmpty(), user.getScmAccountsAsList(), | |||||
scm -> userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(scm))); | |||||
ofNullable(emptyToNull(user.getEmail())).ifPresent(u -> userBuilder.setAvatar(avatarResolver.create(user))); | |||||
userBuilder.setActive(user.isActive()); | |||||
userBuilder.setLocal(user.isLocal()); | |||||
ofNullable(user.getExternalIdentityProvider()).ifPresent(userBuilder::setExternalProvider); | |||||
if (!user.getScmAccountsAsList().isEmpty()) { | |||||
userBuilder.setScmAccounts(ScmAccounts.newBuilder().addAllScmAccounts(user.getScmAccountsAsList())); | |||||
} | |||||
} | } | ||||
if (userSession.isSystemAdministrator() || Objects.equals(userSession.getUuid(), user.getUuid())) { | if (userSession.isSystemAdministrator() || Objects.equals(userSession.getUuid(), user.getUuid())) { | ||||
setIfNeeded(FIELD_EMAIL, fields, user.getEmail(), userBuilder::setEmail); | |||||
setIfNeeded(isNeeded(FIELD_GROUPS, fields) && !groups.isEmpty(), groups, | |||||
g -> userBuilder.setGroups(Groups.newBuilder().addAllGroups(g))); | |||||
setIfNeeded(FIELD_EXTERNAL_IDENTITY, fields, user.getExternalLogin(), userBuilder::setExternalIdentity); | |||||
setIfNeeded(FIELD_TOKENS_COUNT, fields, tokensCount, userBuilder::setTokensCount); | |||||
ofNullable(user.getEmail()).ifPresent(userBuilder::setEmail); | |||||
if (!groups.isEmpty()) { | |||||
userBuilder.setGroups(Groups.newBuilder().addAllGroups(groups)); | |||||
} | |||||
ofNullable(user.getExternalLogin()).ifPresent(userBuilder::setExternalIdentity); | |||||
ofNullable(tokensCount).ifPresent(userBuilder::setTokensCount); | |||||
ofNullable(user.getLastConnectionDate()).ifPresent(date -> userBuilder.setLastConnectionDate(formatDateTime(date))); | ofNullable(user.getLastConnectionDate()).ifPresent(date -> userBuilder.setLastConnectionDate(formatDateTime(date))); | ||||
} | } | ||||
return userBuilder.build(); | return userBuilder.build(); | ||||
} | } | ||||
private static <PARAM> void setIfNeeded(String field, @Nullable Collection<String> fields, @Nullable PARAM parameter, Function<PARAM, ?> setter) { | |||||
setIfNeeded(isNeeded(field, fields), parameter, setter); | |||||
} | |||||
private static <PARAM> void setIfNeeded(boolean condition, @Nullable PARAM parameter, Function<PARAM, ?> setter) { | |||||
if (parameter != null && condition) { | |||||
setter.apply(parameter); | |||||
} | |||||
} | |||||
private static boolean isNeeded(String field, @Nullable Collection<String> fields) { | |||||
return fields == null || fields.isEmpty() || fields.contains(field); | |||||
} | |||||
private static SearchRequest toSearchRequest(Request request) { | private static SearchRequest toSearchRequest(Request request) { | ||||
int pageSize = request.mandatoryParamAsInt(PAGE_SIZE); | int pageSize = request.mandatoryParamAsInt(PAGE_SIZE); | ||||
checkArgument(pageSize <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %s", PAGE_SIZE, MAX_PAGE_SIZE); | checkArgument(pageSize <= MAX_PAGE_SIZE, "The '%s' parameter must be less than %s", PAGE_SIZE, MAX_PAGE_SIZE); | ||||
.setQuery(request.param(TEXT_QUERY)) | .setQuery(request.param(TEXT_QUERY)) | ||||
.setPage(request.mandatoryParamAsInt(PAGE)) | .setPage(request.mandatoryParamAsInt(PAGE)) | ||||
.setPageSize(pageSize) | .setPageSize(pageSize) | ||||
.setPossibleFields(request.paramAsStrings(FIELDS)) | |||||
.build(); | .build(); | ||||
} | } | ||||
private final Integer page; | private final Integer page; | ||||
private final Integer pageSize; | private final Integer pageSize; | ||||
private final String query; | private final String query; | ||||
private final List<String> possibleFields; | |||||
private SearchRequest(Builder builder) { | private SearchRequest(Builder builder) { | ||||
this.page = builder.page; | this.page = builder.page; | ||||
this.pageSize = builder.pageSize; | this.pageSize = builder.pageSize; | ||||
this.query = builder.query; | this.query = builder.query; | ||||
this.possibleFields = builder.additionalFields; | |||||
} | } | ||||
@CheckForNull | @CheckForNull | ||||
return query; | return query; | ||||
} | } | ||||
public List<String> getPossibleFields() { | |||||
return possibleFields; | |||||
} | |||||
public static Builder builder() { | public static Builder builder() { | ||||
return new Builder(); | return new Builder(); | ||||
} | } | ||||
private Integer page; | private Integer page; | ||||
private Integer pageSize; | private Integer pageSize; | ||||
private String query; | private String query; | ||||
private List<String> additionalFields = new ArrayList<>(); | |||||
private Builder() { | private Builder() { | ||||
// enforce factory method use | // enforce factory method use | ||||
return this; | return this; | ||||
} | } | ||||
public Builder setPossibleFields(List<String> possibleFields) { | |||||
this.additionalFields = possibleFields; | |||||
return this; | |||||
} | |||||
public SearchRequest build() { | public SearchRequest build() { | ||||
return new SearchRequest(this); | return new SearchRequest(this); | ||||
} | } |
import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||
import static org.assertj.core.api.Assertions.tuple; | import static org.assertj.core.api.Assertions.tuple; | ||||
import static org.mockito.Mockito.mock; | import static org.mockito.Mockito.mock; | ||||
import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY; | |||||
import static org.sonar.api.utils.DateUtils.formatDate; | import static org.sonar.api.utils.DateUtils.formatDate; | ||||
import static org.sonar.api.utils.DateUtils.formatDateTime; | import static org.sonar.api.utils.DateUtils.formatDateTime; | ||||
import static org.sonar.db.ce.CeActivityDto.Status.FAILED; | import static org.sonar.db.ce.CeActivityDto.Status.FAILED; | ||||
import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; | import static org.sonar.db.ce.CeTaskCharacteristicDto.PULL_REQUEST; | ||||
import static org.sonar.db.component.BranchType.LONG; | import static org.sonar.db.component.BranchType.LONG; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_ID; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_COMPONENT_QUERY; | |||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MAX_EXECUTED_AT; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_MIN_SUBMITTED_AT; | ||||
import static org.sonar.server.ce.ws.CeWsParameters.PARAM_STATUS; | import static org.sonar.server.ce.ws.CeWsParameters.PARAM_STATUS; | ||||
insertActivity("T2", zookeeper, SUCCESS); | insertActivity("T2", zookeeper, SUCCESS); | ||||
insertActivity("T3", eclipse, SUCCESS); | insertActivity("T3", eclipse, SUCCESS); | ||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); | |||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); | |||||
assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T1", "T2"); | assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T1", "T2"); | ||||
} | } | ||||
logInAsSystemAdministrator(); | logInAsSystemAdministrator(); | ||||
insertActivity("T2", apacheView, SUCCESS); | insertActivity("T2", apacheView, SUCCESS); | ||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); | |||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); | |||||
assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T2"); | assertThat(activityResponse.getTasksList()).extracting("id").containsOnly("T2"); | ||||
} | } | ||||
logInAsSystemAdministrator(); | logInAsSystemAdministrator(); | ||||
insertActivity("T2", apacheApp, SUCCESS); | insertActivity("T2", apacheApp, SUCCESS); | ||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); | |||||
ActivityResponse activityResponse = call(ws.newRequest().setParam(TEXT_QUERY, "apac")); | |||||
assertThat(activityResponse.getTasksList()).extracting(Task::getId).containsOnly("T2"); | assertThat(activityResponse.getTasksList()).extracting(Task::getId).containsOnly("T2"); | ||||
} | } | ||||
@Test | @Test | ||||
public void fail_if_both_filters_on_component_id_and_name() { | public void fail_if_both_filters_on_component_id_and_name() { | ||||
expectedException.expect(BadRequestException.class); | expectedException.expect(BadRequestException.class); | ||||
expectedException.expectMessage("componentId and componentQuery must not be set at the same time"); | |||||
expectedException.expectMessage("componentId and q must not be set at the same time"); | |||||
ws.newRequest() | ws.newRequest() | ||||
.setParam("componentId", "ID1") | .setParam("componentId", "ID1") | ||||
.setParam("componentQuery", "apache") | |||||
.setParam("q", "apache") | |||||
.setMediaType(MediaTypes.PROTOBUF) | .setMediaType(MediaTypes.PROTOBUF) | ||||
.execute(); | .execute(); | ||||
} | } |
public void verify_count_of_added_components() { | public void verify_count_of_added_components() { | ||||
ComponentContainer container = new ComponentContainer(); | ComponentContainer container = new ComponentContainer(); | ||||
new ComponentsWsModule().configure(container); | new ComponentsWsModule().configure(container); | ||||
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 8); | |||||
assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 7); | |||||
} | } | ||||
} | } |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.component.ws; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.server.ws.RemovedWebServiceHandler; | |||||
import org.sonar.server.ws.WsTester; | |||||
import static org.assertj.core.api.Assertions.assertThat; | |||||
public class ResourcesWsTest { | |||||
WebService.Controller controller; | |||||
@Before | |||||
public void setUp() { | |||||
WsTester tester = new WsTester(new ResourcesWs()); | |||||
controller = tester.controller("api/resources"); | |||||
} | |||||
@Test | |||||
public void define_controller() { | |||||
assertThat(controller).isNotNull(); | |||||
assertThat(controller.since()).isEqualTo("2.10"); | |||||
assertThat(controller.description()).isNotEmpty(); | |||||
assertThat(controller.actions()).hasSize(1); | |||||
} | |||||
@Test | |||||
public void define_index_action() { | |||||
WebService.Action action = controller.action("index"); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.handler()).isInstanceOf(RemovedWebServiceHandler.class); | |||||
assertThat(action.responseExampleAsString()).isNotEmpty(); | |||||
assertThat(action.params()).isEmpty(); | |||||
} | |||||
} |
@Test | @Test | ||||
public void fail_if_components_and_components_uuid_params_are_set_at_the_same_time() { | public void fail_if_components_and_components_uuid_params_are_set_at_the_same_time() { | ||||
SearchRequest request = new SearchRequest() | SearchRequest request = new SearchRequest() | ||||
.setComponentKeys(asList("foo")) | |||||
.setComponentUuids(asList("bar")); | |||||
.setComponentKeys(singletonList("foo")) | |||||
.setComponentUuids(singletonList("bar")); | |||||
expectedException.expect(IllegalArgumentException.class); | expectedException.expect(IllegalArgumentException.class); | ||||
expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys, componentUuids, components, componentRoots, componentUuids"); | |||||
expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys and componentUuids"); | |||||
underTest.create(request); | underTest.create(request); | ||||
} | } | ||||
@Test | @Test | ||||
public void fail_if_both_componentRoots_and_componentRootUuids_params_are_set() { | public void fail_if_both_componentRoots_and_componentRootUuids_params_are_set() { | ||||
SearchRequest request = new SearchRequest() | SearchRequest request = new SearchRequest() | ||||
.setComponentRoots(asList("foo")) | |||||
.setComponentRootUuids(asList("bar")); | |||||
.setComponentRoots(singletonList("foo")) | |||||
.setComponentRootUuids(singletonList("bar")); | |||||
expectedException.expect(IllegalArgumentException.class); | expectedException.expect(IllegalArgumentException.class); | ||||
expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys, componentUuids, components, componentRoots, componentUuids"); | |||||
expectedException.expectMessage("At most one of the following parameters can be provided: componentKeys and componentUuids"); | |||||
underTest.create(request); | underTest.create(request); | ||||
} | } |
import org.sonar.server.exceptions.UnauthorizedException; | import org.sonar.server.exceptions.UnauthorizedException; | ||||
import org.sonar.server.issue.IssueFieldsSetter; | import org.sonar.server.issue.IssueFieldsSetter; | ||||
import org.sonar.server.issue.IssueFinder; | import org.sonar.server.issue.IssueFinder; | ||||
import org.sonar.server.issue.WebIssueStorage; | |||||
import org.sonar.server.issue.IssueUpdater; | import org.sonar.server.issue.IssueUpdater; | ||||
import org.sonar.server.issue.TestIssueChangePostProcessor; | import org.sonar.server.issue.TestIssueChangePostProcessor; | ||||
import org.sonar.server.issue.WebIssueStorage; | |||||
import org.sonar.server.issue.index.IssueIndexer; | import org.sonar.server.issue.index.IssueIndexer; | ||||
import org.sonar.server.issue.index.IssueIteratorFactory; | import org.sonar.server.issue.index.IssueIteratorFactory; | ||||
import org.sonar.server.notification.NotificationManager; | import org.sonar.server.notification.NotificationManager; | ||||
assertThat(issueChangePostProcessor.wasCalled()).isFalse(); | assertThat(issueChangePostProcessor.wasCalled()).isFalse(); | ||||
} | } | ||||
@Test | |||||
public void assign_to_me_using_deprecated_me_param() { | |||||
IssueDto issue = newIssueWithBrowsePermission(); | |||||
ws.newRequest() | |||||
.setParam("issue", issue.getKey()) | |||||
.setParam("me", "true") | |||||
.execute(); | |||||
checkIssueAssignee(issue.getKey(), CURRENT_USER_UUID); | |||||
Optional<IssueDto> optionalIssueDto = dbClient.issueDao().selectByKey(session, issue.getKey()); | |||||
assertThat(optionalIssueDto).isPresent(); | |||||
assertThat(optionalIssueDto.get().getAssigneeUuid()).isEqualTo(CURRENT_USER_UUID); | |||||
} | |||||
@Test | @Test | ||||
public void unassign() { | public void unassign() { | ||||
IssueDto issue = newIssueWithBrowsePermission(); | IssueDto issue = newIssueWithBrowsePermission(); | ||||
UserDto arthur = insertUser("arthur"); | UserDto arthur = insertUser("arthur"); | ||||
expectedException.expect(IllegalArgumentException.class); | expectedException.expect(IllegalArgumentException.class); | ||||
expectedException.expectMessage("It is not allowed to assign a security hotspot"); | |||||
expectedException.expectMessage("Assigning security hotspots is not allowed"); | |||||
ws.newRequest() | ws.newRequest() | ||||
.setParam("issue", issueDto.getKey()) | .setParam("issue", issueDto.getKey()) |
assertThat(action.key()).isEqualTo("bulk_change"); | assertThat(action.key()).isEqualTo("bulk_change"); | ||||
assertThat(action.isPost()).isTrue(); | assertThat(action.isPost()).isTrue(); | ||||
assertThat(action.isInternal()).isFalse(); | assertThat(action.isInternal()).isFalse(); | ||||
assertThat(action.params()).hasSize(10); | |||||
assertThat(action.params()).hasSize(9); | |||||
assertThat(action.responseExample()).isNotNull(); | assertThat(action.responseExample()).isNotNull(); | ||||
} | } | ||||
import static org.sonar.db.component.ComponentTesting.newView; | import static org.sonar.db.component.ComponentTesting.newView; | ||||
import static org.sonar.db.issue.IssueTesting.newIssue; | import static org.sonar.db.issue.IssueTesting.newIssue; | ||||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; | import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_UUIDS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DIRECTORIES; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_DIRECTORIES; | ||||
indexIssues(); | indexIssues(); | ||||
ws.newRequest() | ws.newRequest() | ||||
.setParam(PARAM_COMPONENTS, file.getDbKey()) | |||||
.setParam(PARAM_COMPONENT_KEYS, file.getKey()) | |||||
.execute() | .execute() | ||||
.assertJson(this.getClass(), "search_by_file_key.json"); | .assertJson(this.getClass(), "search_by_file_key.json"); | ||||
ws.newRequest() | ws.newRequest() | ||||
.setParam(PARAM_COMPONENTS, unitTest.getDbKey()) | |||||
.setParam(PARAM_COMPONENT_KEYS, unitTest.getKey()) | |||||
.execute() | .execute() | ||||
.assertJson(this.getClass(), "search_by_test_key.json"); | .assertJson(this.getClass(), "search_by_test_key.json"); | ||||
} | } |
import static org.sonar.server.tester.UserSessionRule.standalone; | import static org.sonar.server.tester.UserSessionRule.standalone; | ||||
import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; | import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENTS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS; | |||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_CREATED_AFTER; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_HIDE_COMMENTS; | ||||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PAGE_INDEX; | import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PAGE_INDEX; | ||||
session.commit(); | session.commit(); | ||||
indexIssues(); | indexIssues(); | ||||
ws.newRequest().setParam(PARAM_COMPONENTS, file.getDbKey()).execute() | |||||
ws.newRequest().setParam(PARAM_COMPONENT_KEYS, file.getKey()).execute() | |||||
.assertJson(this.getClass(), "apply_paging_with_one_component.json"); | .assertJson(this.getClass(), "apply_paging_with_one_component.json"); | ||||
} | } | ||||
assertThat(def.responseExampleAsString()).isNotEmpty(); | assertThat(def.responseExampleAsString()).isNotEmpty(); | ||||
assertThat(def.params()).extracting("key").containsExactlyInAnyOrder( | assertThat(def.params()).extracting("key").containsExactlyInAnyOrder( | ||||
"additionalFields", "asc", "assigned", "assignees", "authors", "author", "componentKeys", "componentRootUuids", "componentRoots", "componentUuids", "components", "branch", | |||||
"additionalFields", "asc", "assigned", "assignees", "authors", "author", "componentKeys", "componentUuids", "branch", | |||||
"pullRequest", "organization", | "pullRequest", "organization", | ||||
"createdAfter", "createdAt", "createdBefore", "createdInLast", "directories", "facetMode", "facets", "fileUuids", "issues", "languages", "moduleUuids", "onComponentOnly", | "createdAfter", "createdAt", "createdBefore", "createdInLast", "directories", "facetMode", "facets", "fileUuids", "issues", "languages", "moduleUuids", "onComponentOnly", | ||||
"p", "projects", "ps", "resolutions", "resolved", "rules", "s", "severities", "sinceLeakPeriod", | "p", "projects", "ps", "resolutions", "resolved", "rules", "s", "severities", "sinceLeakPeriod", |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.qualityprofile.ws; | |||||
import org.junit.Before; | |||||
import org.junit.Test; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.server.ws.RemovedWebServiceHandler; | |||||
import org.sonar.server.ws.WsTester; | |||||
import static org.assertj.core.api.Assertions.assertThat; | |||||
public class ProfilesWsTest { | |||||
private WsTester ws; | |||||
@Before | |||||
public void setUp() { | |||||
ws = new WsTester(new ProfilesWs()); | |||||
} | |||||
@Test | |||||
public void define_controller() { | |||||
WebService.Controller controller = controller(); | |||||
assertThat(controller).isNotNull(); | |||||
assertThat(controller.path()).isEqualTo("api/profiles"); | |||||
assertThat(controller.description()).isNotEmpty(); | |||||
assertThat(controller.actions()).hasSize(2); | |||||
} | |||||
@Test | |||||
public void define_index_action() { | |||||
WebService.Controller controller = ws.controller("api/profiles"); | |||||
WebService.Action restoreProfiles = controller.action("index"); | |||||
assertThat(restoreProfiles).isNotNull(); | |||||
assertThat(restoreProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); | |||||
assertThat(restoreProfiles.responseExampleAsString()).isNotEmpty(); | |||||
assertThat(restoreProfiles.params()).isEmpty(); | |||||
} | |||||
@Test | |||||
public void define_list_action() { | |||||
WebService.Controller controller = controller(); | |||||
WebService.Action listProfiles = controller.action("list"); | |||||
assertThat(listProfiles).isNotNull(); | |||||
assertThat(listProfiles.handler()).isInstanceOf(RemovedWebServiceHandler.class); | |||||
assertThat(listProfiles.responseExampleAsString()).isNotEmpty(); | |||||
assertThat(listProfiles.params()).isEmpty(); | |||||
} | |||||
private WebService.Controller controller() { | |||||
return ws.controller("api/profiles"); | |||||
} | |||||
} |
import org.sonar.db.organization.OrganizationDto; | import org.sonar.db.organization.OrganizationDto; | ||||
import org.sonar.db.rule.RuleDefinitionDto; | import org.sonar.db.rule.RuleDefinitionDto; | ||||
import org.sonar.db.rule.RuleMetadataDto; | import org.sonar.db.rule.RuleMetadataDto; | ||||
import org.sonar.db.rule.RuleTesting; | |||||
import org.sonar.db.user.UserDto; | import org.sonar.db.user.UserDto; | ||||
import org.sonar.server.es.EsClient; | import org.sonar.server.es.EsClient; | ||||
import org.sonar.server.es.EsTester; | import org.sonar.server.es.EsTester; | ||||
import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; | import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES; | ||||
import static org.sonar.db.rule.RuleTesting.setSystemTags; | import static org.sonar.db.rule.RuleTesting.setSystemTags; | ||||
import static org.sonar.db.rule.RuleTesting.setTags; | import static org.sonar.db.rule.RuleTesting.setTags; | ||||
import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_COEFF; | |||||
import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_OFFSET; | |||||
import static org.sonar.server.rule.ws.UpdateAction.DEPRECATED_PARAM_REMEDIATION_FN_TYPE; | |||||
import static org.sonar.server.rule.ws.UpdateAction.PARAM_KEY; | import static org.sonar.server.rule.ws.UpdateAction.PARAM_KEY; | ||||
import static org.sonar.server.rule.ws.UpdateAction.PARAM_MARKDOWN_NOTE; | import static org.sonar.server.rule.ws.UpdateAction.PARAM_MARKDOWN_NOTE; | ||||
import static org.sonar.server.rule.ws.UpdateAction.PARAM_ORGANIZATION; | import static org.sonar.server.rule.ws.UpdateAction.PARAM_ORGANIZATION; | ||||
assertThat(ws.getDef().responseExampleAsString()).isNotNull(); | assertThat(ws.getDef().responseExampleAsString()).isNotNull(); | ||||
assertThat(ws.getDef().description()).isNotNull(); | assertThat(ws.getDef().description()).isNotNull(); | ||||
} | } | ||||
@Test | @Test | ||||
public void update_custom_rule() { | public void update_custom_rule() { | ||||
logInAsQProfileAdministrator(); | logInAsQProfileAdministrator(); | ||||
assertThat(metadataOfSpecificOrg.getRemediationBaseEffort()).isEqualTo(newEffort); | assertThat(metadataOfSpecificOrg.getRemediationBaseEffort()).isEqualTo(newEffort); | ||||
} | } | ||||
@Test | |||||
public void update_custom_rule_with_deprecated_remediation_function_parameters() { | |||||
logInAsQProfileAdministrator(); | |||||
RuleDefinitionDto rule = RuleTesting.newRule() | |||||
.setDefRemediationFunction(LINEAR_OFFSET.toString()) | |||||
.setDefRemediationGapMultiplier("10d") | |||||
.setDefRemediationBaseEffort("5min"); | |||||
db.rules().insert(rule); | |||||
String newType = LINEAR_OFFSET.toString(); | |||||
String newCoeff = "11d"; | |||||
String newOffset = "6min"; | |||||
Rules.UpdateResponse result = ws.newRequest().setMethod("POST") | |||||
.setParam(PARAM_KEY, rule.getKey().toString()) | |||||
.setParam(DEPRECATED_PARAM_REMEDIATION_FN_TYPE, newType) | |||||
.setParam(DEPRECATED_PARAM_REMEDIATION_FN_COEFF, newCoeff) | |||||
.setParam(DEPRECATED_PARAM_REMEDIATION_FN_OFFSET, newOffset) | |||||
.executeProtobuf(Rules.UpdateResponse.class); | |||||
Rules.Rule updatedRule = result.getRule(); | |||||
assertThat(updatedRule).isNotNull(); | |||||
assertThat(updatedRule.getKey()).isEqualTo(rule.getKey().toString()); | |||||
assertThat(updatedRule.getDefaultRemFnType()).isEqualTo(rule.getDefRemediationFunction()); | |||||
assertThat(updatedRule.getDefaultRemFnGapMultiplier()).isEqualTo(rule.getDefRemediationGapMultiplier()); | |||||
assertThat(updatedRule.getDefaultRemFnBaseEffort()).isEqualTo(rule.getDefRemediationBaseEffort()); | |||||
assertThat(updatedRule.getEffortToFixDescription()).isEqualTo(rule.getGapDescription()); | |||||
assertThat(updatedRule.getRemFnType()).isEqualTo(newType); | |||||
assertThat(updatedRule.getDebtRemFnCoeff()).isEqualTo(newCoeff); | |||||
assertThat(updatedRule.getDebtRemFnOffset()).isEqualTo(newOffset); | |||||
assertThat(updatedRule.getRemFnType()).isEqualTo(newType); | |||||
assertThat(updatedRule.getRemFnGapMultiplier()).isEqualTo(newCoeff); | |||||
assertThat(updatedRule.getRemFnBaseEffort()).isEqualTo(newOffset); | |||||
assertThat(updatedRule.getGapDescription()).isEqualTo(rule.getGapDescription()); | |||||
} | |||||
@Test | @Test | ||||
public void update_note() { | public void update_note() { | ||||
OrganizationDto organization = db.organizations().insert(); | OrganizationDto organization = db.organizations().insert(); |
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.sonar.api.config.internal.MapSettings; | import org.sonar.api.config.internal.MapSettings; | ||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; | import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; | ||||
import org.sonar.db.DbTester; | import org.sonar.db.DbTester; | ||||
.execute(); | .execute(); | ||||
} | } | ||||
@Test | |||||
public void test_definition() { | |||||
WebService.Action action = tester.getDef(); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(3); | |||||
} | |||||
private void createLocalUser() { | private void createLocalUser() { | ||||
db.users().insertUser(newLocalUser("john", "John", "john@email.com")); | db.users().insertUser(newLocalUser("john", "John", "john@email.com")); | ||||
} | } |
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.mockito.ArgumentCaptor; | import org.mockito.ArgumentCaptor; | ||||
import org.sonar.api.config.internal.MapSettings; | import org.sonar.api.config.internal.MapSettings; | ||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; | import org.sonar.api.utils.internal.AlwaysIncreasingSystem2; | ||||
import org.sonar.core.config.CorePropertyDefinitions; | import org.sonar.core.config.CorePropertyDefinitions; | ||||
executeRequest("john"); | executeRequest("john"); | ||||
} | } | ||||
@Test | |||||
public void test_definition() { | |||||
WebService.Action action = tester.getDef(); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(7); | |||||
} | |||||
private CreateWsResponse executeRequest(String login) { | private CreateWsResponse executeRequest(String login) { | ||||
return call(CreateRequest.builder() | return call(CreateRequest.builder() | ||||
.setLogin(login) | .setLogin(login) |
import java.util.stream.IntStream; | import java.util.stream.IntStream; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.api.server.ws.WebService.Param; | import org.sonar.api.server.ws.WebService.Param; | ||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.db.DbTester; | import org.sonar.db.DbTester; | ||||
userSession.logIn(user); | userSession.logIn(user); | ||||
assertThat(ws.newRequest().setParam("q", user.getLogin()) | assertThat(ws.newRequest().setParam("q", user.getLogin()) | ||||
.executeProtobuf(SearchWsResponse.class).getUsersList()) | .executeProtobuf(SearchWsResponse.class).getUsersList()) | ||||
.extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, | |||||
User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate) | |||||
.containsExactlyInAnyOrder( | |||||
tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true)); | |||||
.extracting(User::getLogin, User::getName, User::getEmail, User::getExternalIdentity, User::getExternalProvider, | |||||
User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::getTokensCount, User::hasLastConnectionDate) | |||||
.containsExactlyInAnyOrder( | |||||
tuple(user.getLogin(), user.getName(), user.getEmail(), user.getExternalLogin(), user.getExternalIdentityProvider(), true, true, true, 2, true)); | |||||
userSession.logIn(otherUser); | userSession.logIn(otherUser); | ||||
assertThat(ws.newRequest().setParam("q", user.getLogin()) | assertThat(ws.newRequest().setParam("q", user.getLogin()) | ||||
.executeProtobuf(SearchWsResponse.class).getUsersList()) | .executeProtobuf(SearchWsResponse.class).getUsersList()) | ||||
.extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, | |||||
User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) | |||||
.containsExactlyInAnyOrder( | |||||
tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); | |||||
} | |||||
@Test | |||||
public void search_with_fields() { | |||||
UserDto user = db.users().insertUser(); | |||||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization()); | |||||
db.users().insertMember(group, user); | |||||
userIndexer.indexOnStartup(null); | |||||
userSession.logIn().setSystemAdministrator(); | |||||
assertThat(ws.newRequest() | |||||
.setParam(Param.FIELDS, "scmAccounts") | |||||
.executeProtobuf(SearchWsResponse.class) | |||||
.getUsersList()) | |||||
.extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) | |||||
.containsExactlyInAnyOrder(tuple(user.getLogin(), false, true, false, false)); | |||||
assertThat(ws.newRequest() | |||||
.setParam(Param.FIELDS, "groups") | |||||
.executeProtobuf(SearchWsResponse.class) | |||||
.getUsersList()) | |||||
.extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) | |||||
.containsExactlyInAnyOrder(tuple(user.getLogin(), false, false, false, true)); | |||||
assertThat(ws.newRequest() | |||||
.setParam(Param.FIELDS, "") | |||||
.executeProtobuf(SearchWsResponse.class) | |||||
.getUsersList()) | |||||
.extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) | |||||
.containsExactlyInAnyOrder(tuple(user.getLogin(), true, true, true, true)); | |||||
assertThat(ws.newRequest() | |||||
.executeProtobuf(SearchWsResponse.class) | |||||
.getUsersList()) | |||||
.extracting(User::getLogin, User::hasName, User::hasScmAccounts, User::hasAvatar, User::hasGroups) | |||||
.containsExactlyInAnyOrder(tuple(user.getLogin(), true, true, true, true)); | |||||
.extracting(User::getLogin, User::getName, User::hasEmail, User::hasExternalIdentity, User::hasExternalProvider, | |||||
User::hasScmAccounts, User::hasAvatar, User::hasGroups, User::hasTokensCount, User::hasLastConnectionDate) | |||||
.containsExactlyInAnyOrder( | |||||
tuple(user.getLogin(), user.getName(), false, false, true, true, true, false, false, false)); | |||||
} | } | ||||
@Test | @Test | ||||
assertJson(response).isSimilarTo(getClass().getResource("search-example.json")); | assertJson(response).isSimilarTo(getClass().getResource("search-example.json")); | ||||
} | } | ||||
@Test | |||||
public void test_definition() { | |||||
WebService.Action action = ws.getDef(); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isFalse(); | |||||
assertThat(action.responseExampleAsString()).isNotEmpty(); | |||||
assertThat(action.params()).hasSize(3); | |||||
} | |||||
} | } |
import org.junit.Test; | import org.junit.Test; | ||||
import org.junit.rules.ExpectedException; | import org.junit.rules.ExpectedException; | ||||
import org.sonar.api.config.internal.MapSettings; | import org.sonar.api.config.internal.MapSettings; | ||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.api.utils.System2; | import org.sonar.api.utils.System2; | ||||
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import org.sonar.db.DbSession; | import org.sonar.db.DbSession; | ||||
.execute(); | .execute(); | ||||
} | } | ||||
@Test | |||||
public void test_definition() { | |||||
WebService.Action action = ws.getDef(); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(5); | |||||
} | |||||
private void createUser() { | private void createUser() { | ||||
UserDto userDto = newUserDto() | UserDto userDto = newUserDto() | ||||
.setEmail("john@email.com") | .setEmail("john@email.com") |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.user.ws; | |||||
import org.junit.Before; | |||||
import org.junit.Rule; | |||||
import org.junit.Test; | |||||
import org.sonar.api.server.ws.WebService; | |||||
import org.sonar.db.DbClient; | |||||
import org.sonar.db.DbTester; | |||||
import org.sonar.server.authentication.CredentialsLocalAuthentication; | |||||
import org.sonar.server.issue.ws.AvatarResolver; | |||||
import org.sonar.server.tester.UserSessionRule; | |||||
import org.sonar.server.user.UserUpdater; | |||||
import org.sonar.server.user.index.UserIndex; | |||||
import org.sonar.server.ws.WsTester; | |||||
import static org.assertj.core.api.Assertions.assertThat; | |||||
import static org.mockito.Mockito.mock; | |||||
public class UsersWsTest { | |||||
@Rule | |||||
public UserSessionRule userSessionRule = UserSessionRule.standalone(); | |||||
@Rule | |||||
public DbTester db = DbTester.create(); | |||||
private WebService.Controller controller; | |||||
private CredentialsLocalAuthentication localAuthentication = new CredentialsLocalAuthentication(db.getDbClient()); | |||||
@Before | |||||
public void setUp() { | |||||
WsTester tester = new WsTester(new UsersWs( | |||||
new CreateAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule), | |||||
new UpdateAction(mock(UserUpdater.class), userSessionRule, mock(UserJsonWriter.class), mock(DbClient.class)), | |||||
new ChangePasswordAction(mock(DbClient.class), mock(UserUpdater.class), userSessionRule, localAuthentication), | |||||
new SearchAction(userSessionRule, mock(UserIndex.class), mock(DbClient.class), mock(AvatarResolver.class)))); | |||||
controller = tester.controller("api/users"); | |||||
} | |||||
@Test | |||||
public void define_controller() { | |||||
assertThat(controller).isNotNull(); | |||||
assertThat(controller.description()).isNotEmpty(); | |||||
assertThat(controller.since()).isEqualTo("3.6"); | |||||
assertThat(controller.actions()).hasSize(4); | |||||
} | |||||
@Test | |||||
public void define_search_action() { | |||||
WebService.Action action = controller.action("search"); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isFalse(); | |||||
assertThat(action.responseExampleAsString()).isNotEmpty(); | |||||
assertThat(action.params()).hasSize(4); | |||||
} | |||||
@Test | |||||
public void define_create_action() { | |||||
WebService.Action action = controller.action("create"); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(7); | |||||
} | |||||
@Test | |||||
public void define_update_action() { | |||||
WebService.Action action = controller.action("update"); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(5); | |||||
} | |||||
@Test | |||||
public void define_change_password_action() { | |||||
WebService.Action action = controller.action("change_password"); | |||||
assertThat(action).isNotNull(); | |||||
assertThat(action.isPost()).isTrue(); | |||||
assertThat(action.params()).hasSize(3); | |||||
} | |||||
} |
import org.sonarqube.ws.client.organizations.OrganizationsService; | import org.sonarqube.ws.client.organizations.OrganizationsService; | ||||
import org.sonarqube.ws.client.permissions.PermissionsService; | import org.sonarqube.ws.client.permissions.PermissionsService; | ||||
import org.sonarqube.ws.client.plugins.PluginsService; | import org.sonarqube.ws.client.plugins.PluginsService; | ||||
import org.sonarqube.ws.client.profiles.ProfilesService; | |||||
import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; | import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; | ||||
import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; | import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; | ||||
import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; | import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; | ||||
import org.sonarqube.ws.client.properties.PropertiesService; | import org.sonarqube.ws.client.properties.PropertiesService; | ||||
import org.sonarqube.ws.client.qualitygates.QualitygatesService; | import org.sonarqube.ws.client.qualitygates.QualitygatesService; | ||||
import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; | import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; | ||||
import org.sonarqube.ws.client.resources.ResourcesService; | |||||
import org.sonarqube.ws.client.roots.RootsService; | import org.sonarqube.ws.client.roots.RootsService; | ||||
import org.sonarqube.ws.client.rules.RulesService; | import org.sonarqube.ws.client.rules.RulesService; | ||||
import org.sonarqube.ws.client.securityreports.SecurityReportsService; | import org.sonarqube.ws.client.securityreports.SecurityReportsService; | ||||
private final OrganizationsService organizationsService; | private final OrganizationsService organizationsService; | ||||
private final PermissionsService permissionsService; | private final PermissionsService permissionsService; | ||||
private final PluginsService pluginsService; | private final PluginsService pluginsService; | ||||
private final ProfilesService profilesService; | |||||
private final ProjectAnalysesService projectAnalysesService; | private final ProjectAnalysesService projectAnalysesService; | ||||
private final ProjectBadgesService projectBadgesService; | private final ProjectBadgesService projectBadgesService; | ||||
private final ProjectBranchesService projectBranchesService; | private final ProjectBranchesService projectBranchesService; | ||||
private final PropertiesService propertiesService; | private final PropertiesService propertiesService; | ||||
private final QualitygatesService qualitygatesService; | private final QualitygatesService qualitygatesService; | ||||
private final QualityprofilesService qualityprofilesService; | private final QualityprofilesService qualityprofilesService; | ||||
private final ResourcesService resourcesService; | |||||
private final RootsService rootsService; | private final RootsService rootsService; | ||||
private final RulesService rulesService; | private final RulesService rulesService; | ||||
private final ServerService serverService; | private final ServerService serverService; | ||||
this.organizationsService = new OrganizationsService(wsConnector); | this.organizationsService = new OrganizationsService(wsConnector); | ||||
this.permissionsService = new PermissionsService(wsConnector); | this.permissionsService = new PermissionsService(wsConnector); | ||||
this.pluginsService = new PluginsService(wsConnector); | this.pluginsService = new PluginsService(wsConnector); | ||||
this.profilesService = new ProfilesService(wsConnector); | |||||
this.projectAnalysesService = new ProjectAnalysesService(wsConnector); | this.projectAnalysesService = new ProjectAnalysesService(wsConnector); | ||||
this.projectBadgesService = new ProjectBadgesService(wsConnector); | this.projectBadgesService = new ProjectBadgesService(wsConnector); | ||||
this.projectBranchesService = new ProjectBranchesService(wsConnector); | this.projectBranchesService = new ProjectBranchesService(wsConnector); | ||||
this.propertiesService = new PropertiesService(wsConnector); | this.propertiesService = new PropertiesService(wsConnector); | ||||
this.qualitygatesService = new QualitygatesService(wsConnector); | this.qualitygatesService = new QualitygatesService(wsConnector); | ||||
this.qualityprofilesService = new QualityprofilesService(wsConnector); | this.qualityprofilesService = new QualityprofilesService(wsConnector); | ||||
this.resourcesService = new ResourcesService(wsConnector); | |||||
this.rootsService = new RootsService(wsConnector); | this.rootsService = new RootsService(wsConnector); | ||||
this.rulesService = new RulesService(wsConnector); | this.rulesService = new RulesService(wsConnector); | ||||
this.serverService = new ServerService(wsConnector); | this.serverService = new ServerService(wsConnector); | ||||
return pluginsService; | return pluginsService; | ||||
} | } | ||||
@Override | |||||
public ProfilesService profiles() { | |||||
return profilesService; | |||||
} | |||||
@Override | @Override | ||||
public ProjectAnalysesService projectAnalyses() { | public ProjectAnalysesService projectAnalyses() { | ||||
return projectAnalysesService; | return projectAnalysesService; | ||||
return qualityprofilesService; | return qualityprofilesService; | ||||
} | } | ||||
@Override | |||||
public ResourcesService resources() { | |||||
return resourcesService; | |||||
} | |||||
@Override | @Override | ||||
public RootsService roots() { | public RootsService roots() { | ||||
return rootsService; | return rootsService; |
import org.sonarqube.ws.client.organizations.OrganizationsService; | import org.sonarqube.ws.client.organizations.OrganizationsService; | ||||
import org.sonarqube.ws.client.permissions.PermissionsService; | import org.sonarqube.ws.client.permissions.PermissionsService; | ||||
import org.sonarqube.ws.client.plugins.PluginsService; | import org.sonarqube.ws.client.plugins.PluginsService; | ||||
import org.sonarqube.ws.client.profiles.ProfilesService; | |||||
import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; | import org.sonarqube.ws.client.projectanalyses.ProjectAnalysesService; | ||||
import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; | import org.sonarqube.ws.client.projectbadges.ProjectBadgesService; | ||||
import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; | import org.sonarqube.ws.client.projectbranches.ProjectBranchesService; | ||||
import org.sonarqube.ws.client.properties.PropertiesService; | import org.sonarqube.ws.client.properties.PropertiesService; | ||||
import org.sonarqube.ws.client.qualitygates.QualitygatesService; | import org.sonarqube.ws.client.qualitygates.QualitygatesService; | ||||
import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; | import org.sonarqube.ws.client.qualityprofiles.QualityprofilesService; | ||||
import org.sonarqube.ws.client.resources.ResourcesService; | |||||
import org.sonarqube.ws.client.roots.RootsService; | import org.sonarqube.ws.client.roots.RootsService; | ||||
import org.sonarqube.ws.client.rules.RulesService; | import org.sonarqube.ws.client.rules.RulesService; | ||||
import org.sonarqube.ws.client.securityreports.SecurityReportsService; | import org.sonarqube.ws.client.securityreports.SecurityReportsService; | ||||
PluginsService plugins(); | PluginsService plugins(); | ||||
ProfilesService profiles(); | |||||
ProjectAnalysesService projectAnalyses(); | ProjectAnalysesService projectAnalyses(); | ||||
ProjectBadgesService projectBadges(); | ProjectBadgesService projectBadges(); | ||||
QualityprofilesService qualityprofiles(); | QualityprofilesService qualityprofiles(); | ||||
ResourcesService resources(); | |||||
RootsService roots(); | RootsService roots(); | ||||
RulesService rules(); | RulesService rules(); |
public class ActivityRequest { | public class ActivityRequest { | ||||
private String componentId; | private String componentId; | ||||
private String componentQuery; | |||||
private String maxExecutedAt; | private String maxExecutedAt; | ||||
private String minSubmittedAt; | private String minSubmittedAt; | ||||
private String onlyCurrents; | private String onlyCurrents; | ||||
private String p; | |||||
private String ps; | private String ps; | ||||
private String q; | private String q; | ||||
private List<String> status; | private List<String> status; | ||||
return componentId; | return componentId; | ||||
} | } | ||||
/** | |||||
* Example value: "Apache" | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public ActivityRequest setComponentQuery(String componentQuery) { | |||||
this.componentQuery = componentQuery; | |||||
return this; | |||||
} | |||||
public String getComponentQuery() { | |||||
return componentQuery; | |||||
} | |||||
/** | /** | ||||
* Example value: "2017-10-19T13:00:00+0200" | * Example value: "2017-10-19T13:00:00+0200" | ||||
*/ | */ | ||||
return onlyCurrents; | return onlyCurrents; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public ActivityRequest setP(String p) { | |||||
this.p = p; | |||||
return this; | |||||
} | |||||
public String getP() { | |||||
return p; | |||||
} | |||||
/** | /** | ||||
* Example value: "20" | * Example value: "20" | ||||
*/ | */ |
return call( | return call( | ||||
new GetRequest(path("activity")) | new GetRequest(path("activity")) | ||||
.setParam("componentId", request.getComponentId()) | .setParam("componentId", request.getComponentId()) | ||||
.setParam("componentQuery", request.getComponentQuery()) | |||||
.setParam("maxExecutedAt", request.getMaxExecutedAt()) | .setParam("maxExecutedAt", request.getMaxExecutedAt()) | ||||
.setParam("minSubmittedAt", request.getMinSubmittedAt()) | .setParam("minSubmittedAt", request.getMinSubmittedAt()) | ||||
.setParam("onlyCurrents", request.getOnlyCurrents()) | .setParam("onlyCurrents", request.getOnlyCurrents()) | ||||
.setParam("p", request.getP()) | |||||
.setParam("ps", request.getPs()) | .setParam("ps", request.getPs()) | ||||
.setParam("q", request.getQ()) | .setParam("q", request.getQ()) | ||||
.setParam("status", request.getStatus() == null ? null : request.getStatus().stream().collect(Collectors.joining(","))) | .setParam("status", request.getStatus() == null ? null : request.getStatus().stream().collect(Collectors.joining(","))) |
public static final String PARAM_STATUSES = "statuses"; | public static final String PARAM_STATUSES = "statuses"; | ||||
public static final String PARAM_RESOLUTIONS = "resolutions"; | public static final String PARAM_RESOLUTIONS = "resolutions"; | ||||
public static final String PARAM_RESOLVED = "resolved"; | public static final String PARAM_RESOLVED = "resolved"; | ||||
public static final String PARAM_COMPONENTS = "components"; | |||||
public static final String PARAM_COMPONENT_KEYS = "componentKeys"; | public static final String PARAM_COMPONENT_KEYS = "componentKeys"; | ||||
public static final String PARAM_COMPONENT_UUIDS = "componentUuids"; | public static final String PARAM_COMPONENT_UUIDS = "componentUuids"; | ||||
public static final String PARAM_COMPONENT_ROOTS = "componentRoots"; | |||||
public static final String PARAM_COMPONENT_ROOT_UUIDS = "componentRootUuids"; | |||||
public static final String PARAM_MODULE_UUIDS = "moduleUuids"; | public static final String PARAM_MODULE_UUIDS = "moduleUuids"; | ||||
public static final String PARAM_PROJECTS = "projects"; | public static final String PARAM_PROJECTS = "projects"; | ||||
public static final String PARAM_PROJECT_KEYS = "projectKeys"; | public static final String PARAM_PROJECT_KEYS = "projectKeys"; | ||||
public static final String PARAM_ASSIGN = "assign"; | public static final String PARAM_ASSIGN = "assign"; | ||||
public static final String PARAM_SET_SEVERITY = "set_severity"; | public static final String PARAM_SET_SEVERITY = "set_severity"; | ||||
public static final String PARAM_SET_TYPE = "set_type"; | public static final String PARAM_SET_TYPE = "set_type"; | ||||
public static final String PARAM_PLAN = "plan"; | |||||
public static final String PARAM_DO_TRANSITION = "do_transition"; | public static final String PARAM_DO_TRANSITION = "do_transition"; | ||||
public static final String PARAM_ADD_TAGS = "add_tags"; | public static final String PARAM_ADD_TAGS = "add_tags"; | ||||
public static final String PARAM_REMOVE_TAGS = "remove_tags"; | public static final String PARAM_REMOVE_TAGS = "remove_tags"; | ||||
public static final String PARAM_SEND_NOTIFICATIONS = "sendNotifications"; | public static final String PARAM_SEND_NOTIFICATIONS = "sendNotifications"; | ||||
/** | |||||
* @deprecated since 5.5, action plan feature has been removed | |||||
*/ | |||||
@Deprecated | |||||
public static final String DEPRECATED_PARAM_ACTION_PLANS = "actionPlans"; | |||||
/** | |||||
* @deprecated since 5.5, manual issue feature has been dropped. | |||||
*/ | |||||
@Deprecated | |||||
public static final String PARAM_REPORTERS = "reporters"; | |||||
public static final String PARAM_ASSIGNEES = "assignees"; | public static final String PARAM_ASSIGNEES = "assignees"; | ||||
/** | /** | ||||
public static final String PARAM_SANS_TOP_25 = "sansTop25"; | public static final String PARAM_SANS_TOP_25 = "sansTop25"; | ||||
public static final String PARAM_CWE = "cwe"; | public static final String PARAM_CWE = "cwe"; | ||||
public static final String PARAM_ASSIGNED = "assigned"; | public static final String PARAM_ASSIGNED = "assigned"; | ||||
/** | |||||
* @deprecated since 5.5, action plan feature has been removed | |||||
*/ | |||||
@Deprecated | |||||
public static final String PARAM_PLANNED = "planned"; | |||||
public static final String PARAM_HIDE_COMMENTS = "hideComments"; | public static final String PARAM_HIDE_COMMENTS = "hideComments"; | ||||
public static final String PARAM_CREATED_AFTER = "createdAfter"; | public static final String PARAM_CREATED_AFTER = "createdAfter"; | ||||
public static final String PARAM_CREATED_AT = "createdAt"; | public static final String PARAM_CREATED_AT = "createdAt"; |
*/ | */ | ||||
package org.sonarqube.ws.client.issues; | package org.sonarqube.ws.client.issues; | ||||
import java.util.List; | |||||
import javax.annotation.Generated; | import javax.annotation.Generated; | ||||
/** | /** | ||||
private String assignee; | private String assignee; | ||||
private String issue; | private String issue; | ||||
private String me; | |||||
/** | /** | ||||
* Example value: "admin" | * Example value: "admin" | ||||
return issue; | return issue; | ||||
} | } | ||||
/** | |||||
* Possible values: | |||||
* <ul> | |||||
* <li>"true"</li> | |||||
* <li>"false"</li> | |||||
* <li>"yes"</li> | |||||
* <li>"no"</li> | |||||
* </ul> | |||||
* @deprecated since 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public AssignRequest setMe(String me) { | |||||
this.me = me; | |||||
return this; | |||||
} | |||||
public String getMe() { | |||||
return me; | |||||
} | |||||
} | } |
private List<String> comment; | private List<String> comment; | ||||
private String doTransition; | private String doTransition; | ||||
private List<String> issues; | private List<String> issues; | ||||
private List<String> plan; | |||||
private String removeTags; | private String removeTags; | ||||
private String sendNotifications; | private String sendNotifications; | ||||
private List<String> setSeverity; | private List<String> setSeverity; | ||||
return issues; | return issues; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public BulkChangeRequest setPlan(List<String> plan) { | |||||
this.plan = plan; | |||||
return this; | |||||
} | |||||
public List<String> getPlan() { | |||||
return plan; | |||||
} | |||||
/** | /** | ||||
* Example value: "security,java8" | * Example value: "security,java8" | ||||
*/ | */ |
return call( | return call( | ||||
new PostRequest(path("assign")) | new PostRequest(path("assign")) | ||||
.setParam("assignee", request.getAssignee()) | .setParam("assignee", request.getAssignee()) | ||||
.setParam("issue", request.getIssue()) | |||||
.setParam("me", request.getMe()), | |||||
.setParam("issue", request.getIssue()), | |||||
AssignResponse.parser()); | AssignResponse.parser()); | ||||
} | } | ||||
.setParam("comment", request.getComment() == null ? null : request.getComment().stream().collect(Collectors.joining(","))) | .setParam("comment", request.getComment() == null ? null : request.getComment().stream().collect(Collectors.joining(","))) | ||||
.setParam("do_transition", request.getDoTransition()) | .setParam("do_transition", request.getDoTransition()) | ||||
.setParam("issues", request.getIssues() == null ? null : request.getIssues().stream().collect(Collectors.joining(","))) | .setParam("issues", request.getIssues() == null ? null : request.getIssues().stream().collect(Collectors.joining(","))) | ||||
.setParam("plan", request.getPlan() == null ? null : request.getPlan().stream().collect(Collectors.joining(","))) | |||||
.setParam("remove_tags", request.getRemoveTags()) | .setParam("remove_tags", request.getRemoveTags()) | ||||
.setParam("sendNotifications", request.getSendNotifications()) | .setParam("sendNotifications", request.getSendNotifications()) | ||||
.setParam("set_severity", request.getSetSeverity() == null ? null : request.getSetSeverity().stream().collect(Collectors.joining(","))) | .setParam("set_severity", request.getSetSeverity() == null ? null : request.getSetSeverity().stream().collect(Collectors.joining(","))) | ||||
.setParam("authors", request.getAuthors() == null ? null : request.getAuthors().stream().collect(Collectors.joining(","))) | .setParam("authors", request.getAuthors() == null ? null : request.getAuthors().stream().collect(Collectors.joining(","))) | ||||
.setParam("branch", request.getBranch()) | .setParam("branch", request.getBranch()) | ||||
.setParam("componentKeys", request.getComponentKeys() == null ? null : request.getComponentKeys().stream().collect(Collectors.joining(","))) | .setParam("componentKeys", request.getComponentKeys() == null ? null : request.getComponentKeys().stream().collect(Collectors.joining(","))) | ||||
.setParam("componentRootUuids", request.getComponentRootUuids()) | |||||
.setParam("componentRoots", request.getComponentRoots()) | |||||
.setParam("componentUuids", request.getComponentUuids() == null ? null : request.getComponentUuids().stream().collect(Collectors.joining(","))) | .setParam("componentUuids", request.getComponentUuids() == null ? null : request.getComponentUuids().stream().collect(Collectors.joining(","))) | ||||
.setParam("components", request.getComponents()) | |||||
.setParam("createdAfter", request.getCreatedAfter()) | .setParam("createdAfter", request.getCreatedAfter()) | ||||
.setParam("createdAt", request.getCreatedAt()) | .setParam("createdAt", request.getCreatedAt()) | ||||
.setParam("createdBefore", request.getCreatedBefore()) | .setParam("createdBefore", request.getCreatedBefore()) |
private List<String> authors; | private List<String> authors; | ||||
private String branch; | private String branch; | ||||
private List<String> componentKeys; | private List<String> componentKeys; | ||||
private String componentRootUuids; | |||||
private String componentRoots; | |||||
private List<String> componentUuids; | private List<String> componentUuids; | ||||
private String components; | |||||
private String createdAfter; | private String createdAfter; | ||||
private String createdAt; | private String createdAt; | ||||
private String createdBefore; | private String createdBefore; | ||||
return componentKeys; | return componentKeys; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.1 | |||||
*/ | |||||
@Deprecated | |||||
public SearchRequest setComponentRootUuids(String componentRootUuids) { | |||||
this.componentRootUuids = componentRootUuids; | |||||
return this; | |||||
} | |||||
public String getComponentRootUuids() { | |||||
return componentRootUuids; | |||||
} | |||||
/** | |||||
* @deprecated since 5.1 | |||||
*/ | |||||
@Deprecated | |||||
public SearchRequest setComponentRoots(String componentRoots) { | |||||
this.componentRoots = componentRoots; | |||||
return this; | |||||
} | |||||
public String getComponentRoots() { | |||||
return componentRoots; | |||||
} | |||||
/** | /** | ||||
* Example value: "584a89f2-8037-4f7b-b82c-8b45d2d63fb2" | * Example value: "584a89f2-8037-4f7b-b82c-8b45d2d63fb2" | ||||
* @deprecated since 6.5 | * @deprecated since 6.5 | ||||
return componentUuids; | return componentUuids; | ||||
} | } | ||||
/** | |||||
* @deprecated since 5.1 | |||||
*/ | |||||
@Deprecated | |||||
public SearchRequest setComponents(String components) { | |||||
this.components = components; | |||||
return this; | |||||
} | |||||
public String getComponents() { | |||||
return components; | |||||
} | |||||
/** | /** | ||||
* Example value: "2017-10-19 or 2017-10-19T13:00:00+0200" | * Example value: "2017-10-19 or 2017-10-19T13:00:00+0200" | ||||
*/ | */ |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.profiles; | |||||
import java.util.stream.Collectors; | |||||
import javax.annotation.Generated; | |||||
import org.sonarqube.ws.MediaTypes; | |||||
import org.sonarqube.ws.client.BaseService; | |||||
import org.sonarqube.ws.client.GetRequest; | |||||
import org.sonarqube.ws.client.PostRequest; | |||||
import org.sonarqube.ws.client.WsConnector; | |||||
/** | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles">Further information about this web service online</a> | |||||
*/ | |||||
@Generated("sonar-ws-generator") | |||||
public class ProfilesService extends BaseService { | |||||
public ProfilesService(WsConnector wsConnector) { | |||||
super(wsConnector, "api/profiles"); | |||||
} | |||||
/** | |||||
* | |||||
* This is part of the internal API. | |||||
* This is a GET request. | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles/index">Further information about this action online (including a response example)</a> | |||||
* @since 3.3 | |||||
* @deprecated since 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public String index() { | |||||
return call( | |||||
new GetRequest(path("index")) | |||||
.setMediaType(MediaTypes.JSON) | |||||
).content(); | |||||
} | |||||
/** | |||||
* | |||||
* This is part of the internal API. | |||||
* This is a GET request. | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/profiles/list">Further information about this action online (including a response example)</a> | |||||
* @since 3.3 | |||||
* @deprecated since 5.2 | |||||
*/ | |||||
@Deprecated | |||||
public String list() { | |||||
return call( | |||||
new GetRequest(path("list")) | |||||
.setMediaType(MediaTypes.JSON) | |||||
).content(); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
@Generated("sonar-ws-generator") | |||||
package org.sonarqube.ws.client.profiles; | |||||
import javax.annotation.ParametersAreNonnullByDefault; | |||||
import javax.annotation.Generated; | |||||
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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.resources; | |||||
import javax.annotation.Generated; | |||||
import org.sonarqube.ws.MediaTypes; | |||||
import org.sonarqube.ws.client.BaseService; | |||||
import org.sonarqube.ws.client.GetRequest; | |||||
import org.sonarqube.ws.client.WsConnector; | |||||
/** | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/resources">Further information about this web service online</a> | |||||
*/ | |||||
@Generated("sonar-ws-generator") | |||||
public class ResourcesService extends BaseService { | |||||
public ResourcesService(WsConnector wsConnector) { | |||||
super(wsConnector, "api/resources"); | |||||
} | |||||
/** | |||||
* | |||||
* This is part of the internal API. | |||||
* This is a GET request. | |||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/resources/index">Further information about this action online (including a response example)</a> | |||||
* @since 2.10 | |||||
* @deprecated since 5.4 | |||||
*/ | |||||
@Deprecated | |||||
public String index() { | |||||
return call( | |||||
new GetRequest(path("index")) | |||||
.setMediaType(MediaTypes.JSON) | |||||
).content(); | |||||
} | |||||
} |
/* | |||||
* SonarQube | |||||
* Copyright (C) 2009-2019 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. | |||||
*/ | |||||
@ParametersAreNonnullByDefault | |||||
@Generated("sonar-ws-generator") | |||||
package org.sonarqube.ws.client.resources; | |||||
import javax.annotation.ParametersAreNonnullByDefault; | |||||
import javax.annotation.Generated; | |||||
public class CreateRequest { | public class CreateRequest { | ||||
private String customKey; | private String customKey; | ||||
private String manualKey; | |||||
private String markdownDescription; | private String markdownDescription; | ||||
private String name; | private String name; | ||||
private List<String> params; | private List<String> params; | ||||
return customKey; | return customKey; | ||||
} | } | ||||
/** | |||||
* Example value: "Error_handling" | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public CreateRequest setManualKey(String manualKey) { | |||||
this.manualKey = manualKey; | |||||
return this; | |||||
} | |||||
public String getManualKey() { | |||||
return manualKey; | |||||
} | |||||
/** | /** | ||||
* This is a mandatory parameter. | * This is a mandatory parameter. | ||||
* Example value: "Description of my custom rule" | * Example value: "Description of my custom rule" |
import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
import javax.annotation.Generated; | import javax.annotation.Generated; | ||||
import org.sonarqube.ws.MediaTypes; | import org.sonarqube.ws.MediaTypes; | ||||
import org.sonarqube.ws.client.BaseService; | |||||
import org.sonarqube.ws.client.GetRequest; | |||||
import org.sonarqube.ws.client.PostRequest; | |||||
import org.sonarqube.ws.client.WsConnector; | |||||
import org.sonarqube.ws.Rules.CreateResponse; | import org.sonarqube.ws.Rules.CreateResponse; | ||||
import org.sonarqube.ws.Rules.ListResponse; | import org.sonarqube.ws.Rules.ListResponse; | ||||
import org.sonarqube.ws.Rules.SearchResponse; | import org.sonarqube.ws.Rules.SearchResponse; | ||||
import org.sonarqube.ws.Rules.ShowResponse; | import org.sonarqube.ws.Rules.ShowResponse; | ||||
import org.sonarqube.ws.Rules.UpdateResponse; | import org.sonarqube.ws.Rules.UpdateResponse; | ||||
import org.sonarqube.ws.client.BaseService; | |||||
import org.sonarqube.ws.client.GetRequest; | |||||
import org.sonarqube.ws.client.PostRequest; | |||||
import org.sonarqube.ws.client.WsConnector; | |||||
/** | /** | ||||
* @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules">Further information about this web service online</a> | * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/rules">Further information about this web service online</a> | ||||
call( | call( | ||||
new PostRequest(path("create")) | new PostRequest(path("create")) | ||||
.setParam("custom_key", request.getCustomKey()) | .setParam("custom_key", request.getCustomKey()) | ||||
.setParam("manual_key", request.getManualKey()) | |||||
.setParam("markdown_description", request.getMarkdownDescription()) | .setParam("markdown_description", request.getMarkdownDescription()) | ||||
.setParam("name", request.getName()) | .setParam("name", request.getName()) | ||||
.setParam("params", request.getParams() == null ? null : request.getParams().stream().collect(Collectors.joining(","))) | .setParam("params", request.getParams() == null ? null : request.getParams().stream().collect(Collectors.joining(","))) | ||||
public void update(UpdateRequest request) { | public void update(UpdateRequest request) { | ||||
call( | call( | ||||
new PostRequest(path("update")) | new PostRequest(path("update")) | ||||
.setParam("debt_remediation_fn_offset", request.getDebtRemediationFnOffset()) | |||||
.setParam("debt_remediation_fn_type", request.getDebtRemediationFnType()) | |||||
.setParam("debt_remediation_fy_coeff", request.getDebtRemediationFyCoeff()) | |||||
.setParam("debt_sub_characteristic", request.getDebtSubCharacteristic()) | |||||
.setParam("key", request.getKey()) | .setParam("key", request.getKey()) | ||||
.setParam("markdown_description", request.getMarkdownDescription()) | .setParam("markdown_description", request.getMarkdownDescription()) | ||||
.setParam("markdown_note", request.getMarkdownNote()) | .setParam("markdown_note", request.getMarkdownNote()) |
@Generated("sonar-ws-generator") | @Generated("sonar-ws-generator") | ||||
public class UpdateRequest { | public class UpdateRequest { | ||||
private String debtRemediationFnOffset; | |||||
private String debtRemediationFnType; | |||||
private String debtRemediationFyCoeff; | |||||
private String debtSubCharacteristic; | |||||
private String key; | private String key; | ||||
private String markdownDescription; | private String markdownDescription; | ||||
private String markdownNote; | private String markdownNote; | ||||
private String status; | private String status; | ||||
private List<String> tags; | private List<String> tags; | ||||
/** | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public UpdateRequest setDebtRemediationFnOffset(String debtRemediationFnOffset) { | |||||
this.debtRemediationFnOffset = debtRemediationFnOffset; | |||||
return this; | |||||
} | |||||
public String getDebtRemediationFnOffset() { | |||||
return debtRemediationFnOffset; | |||||
} | |||||
/** | |||||
* Possible values: | |||||
* <ul> | |||||
* <li>"LINEAR"</li> | |||||
* <li>"LINEAR_OFFSET"</li> | |||||
* <li>"CONSTANT_ISSUE"</li> | |||||
* </ul> | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public UpdateRequest setDebtRemediationFnType(String debtRemediationFnType) { | |||||
this.debtRemediationFnType = debtRemediationFnType; | |||||
return this; | |||||
} | |||||
public String getDebtRemediationFnType() { | |||||
return debtRemediationFnType; | |||||
} | |||||
/** | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public UpdateRequest setDebtRemediationFyCoeff(String debtRemediationFyCoeff) { | |||||
this.debtRemediationFyCoeff = debtRemediationFyCoeff; | |||||
return this; | |||||
} | |||||
public String getDebtRemediationFyCoeff() { | |||||
return debtRemediationFyCoeff; | |||||
} | |||||
/** | |||||
* @deprecated since 5.5 | |||||
*/ | |||||
@Deprecated | |||||
public UpdateRequest setDebtSubCharacteristic(String debtSubCharacteristic) { | |||||
this.debtSubCharacteristic = debtSubCharacteristic; | |||||
return this; | |||||
} | |||||
public String getDebtSubCharacteristic() { | |||||
return debtSubCharacteristic; | |||||
} | |||||
/** | /** | ||||
* This is a mandatory parameter. | * This is a mandatory parameter. | ||||
* Example value: "javascript:NullCheck" | * Example value: "javascript:NullCheck" |
*/ | */ | ||||
package org.sonarqube.ws.client.users; | package org.sonarqube.ws.client.users; | ||||
import java.util.List; | |||||
import javax.annotation.Generated; | import javax.annotation.Generated; | ||||
/** | /** | ||||
@Generated("sonar-ws-generator") | @Generated("sonar-ws-generator") | ||||
public class SearchRequest { | public class SearchRequest { | ||||
private List<String> f; | |||||
private String p; | private String p; | ||||
private String ps; | private String ps; | ||||
private String q; | private String q; | ||||
/** | |||||
* Possible values: | |||||
* <ul> | |||||
* <li>"name"</li> | |||||
* <li>"email"</li> | |||||
* <li>"avatart"</li> | |||||
* <li>"scmAccounts"</li> | |||||
* <li>"groups"</li> | |||||
* <li>"active"</li> | |||||
* <li>"local"</li> | |||||
* <li>"externalIdentity"</li> | |||||
* <li>"externalProvider"</li> | |||||
* </ul> | |||||
* @deprecated since 5.4 | |||||
*/ | |||||
@Deprecated | |||||
public SearchRequest setF(List<String> f) { | |||||
this.f = f; | |||||
return this; | |||||
} | |||||
public List<String> getF() { | |||||
return f; | |||||
} | |||||
/** | /** | ||||
* Example value: "42" | * Example value: "42" | ||||
*/ | */ |
public SearchWsResponse search(SearchRequest request) { | public SearchWsResponse search(SearchRequest request) { | ||||
return call( | return call( | ||||
new GetRequest(path("search")) | new GetRequest(path("search")) | ||||
.setParam("f", request.getF() == null ? null : request.getF().stream().collect(Collectors.joining(","))) | |||||
.setParam("p", request.getP()) | .setParam("p", request.getP()) | ||||
.setParam("ps", request.getPs()) | .setParam("ps", request.getPs()) | ||||
.setParam("q", request.getQ()), | .setParam("q", request.getQ()), |