import javax.annotation.concurrent.Immutable;
import org.sonar.db.component.ComponentDto;
+import org.sonar.server.permission.ws.ProjectWsRef;
import static java.util.Objects.requireNonNull;
* Reference to a project by its db id or uuid. The field "id" should
* be removed as soon as backend is fully based on uuids.
*
- * @see org.sonar.server.permission.ws.WsProjectRef
+ * @see ProjectWsRef
*/
@Immutable
public class ProjectId {
/**
* @throws org.sonar.server.exceptions.NotFoundException if a project does not exist
*/
- public ProjectId findProject(DbSession dbSession, WsProjectRef ref) {
+ public ProjectId findProject(DbSession dbSession, ProjectWsRef ref) {
ComponentDto project = componentFinder.getRootComponentOrModuleByUuidOrKey(dbSession, ref.uuid(), ref.key(), resourceTypes);
return new ProjectId(project.getId(), project.uuid());
}
String uuid = request.param(PermissionsWsParameters.PARAM_PROJECT_ID);
String key = request.param(PermissionsWsParameters.PARAM_PROJECT_KEY);
if (uuid != null || key != null) {
- WsProjectRef ref = WsProjectRef.newWsProjectRef(uuid, key);
+ ProjectWsRef ref = ProjectWsRef.newWsProjectRef(uuid, key);
return Optional.of(findProject(dbSession, ref));
}
return Optional.empty();
}
- public ComponentDto getRootComponentOrModule(DbSession dbSession, WsProjectRef projectRef) {
+ public ComponentDto getRootComponentOrModule(DbSession dbSession, ProjectWsRef projectRef) {
return componentFinder.getRootComponentOrModuleByUuidOrKey(dbSession, projectRef.uuid(), projectRef.key(), resourceTypes);
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.permission.ws;
+
+import com.google.common.base.Optional;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static org.sonar.server.ws.WsUtils.checkRequest;
+
+/**
+ * Reference to a project <b>as defined by web service callers</b>. It allows to reference a project
+ * by its (functional) key or by its (technical) id. It's then converted to {@link org.sonar.server.permission.ProjectId}.
+ *
+ * <p>Factory methods guarantee that the project id and project key are not provided at the same time.</p>
+ */
+public class ProjectWsRef {
+ private static final String MSG_ID_OR_KEY_MUST_BE_PROVIDED = "Project id or project key can be provided, not both.";
+ private final String uuid;
+ private final String key;
+
+ private ProjectWsRef(@Nullable String uuid, @Nullable String key) {
+ this.uuid = uuid;
+ this.key = key;
+ checkRequest(this.uuid != null ^ this.key != null, "Project id or project key can be provided, not both.");
+ }
+
+ public static Optional<ProjectWsRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) {
+ if (uuid == null && key == null) {
+ return Optional.absent();
+ }
+
+ return Optional.of(new ProjectWsRef(uuid, key));
+ }
+
+ public static ProjectWsRef newWsProjectRef(@Nullable String uuid, @Nullable String key) {
+ checkRequest(uuid == null ^ key == null, MSG_ID_OR_KEY_MUST_BE_PROVIDED);
+ return new ProjectWsRef(uuid, key);
+ }
+
+ @CheckForNull
+ public String uuid() {
+ return this.uuid;
+ }
+
+ @CheckForNull
+ public String key() {
+ return this.key;
+ }
+}
import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdminUserByComponentUuid;
import static org.sonar.server.permission.ws.PermissionRequestValidator.validateQualifier;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
-import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef;
+import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef;
import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext;
import static org.sonar.server.ws.WsParameterBuilder.createRootQualifierParameter;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
}
private void checkRequestAndPermissions(SearchProjectPermissionsWsRequest request) {
- Optional<WsProjectRef> project = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
+ Optional<ProjectWsRef> project = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
boolean hasProject = project.isPresent();
boolean hasProjectUuid = hasProject && project.get().uuid() != null;
boolean hasProjectKey = hasProject && project.get().key() != null;
import static org.sonar.api.utils.Paging.forPageIndex;
import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
import static org.sonar.server.permission.ws.SearchProjectPermissionsData.newBuilder;
-import static org.sonar.server.permission.ws.WsProjectRef.newOptionalWsProjectRef;
+import static org.sonar.server.permission.ws.ProjectWsRef.newOptionalWsProjectRef;
public class SearchProjectPermissionsDataLoader {
private final DbClient dbClient;
}
private List<ComponentDto> searchRootComponents(DbSession dbSession, SearchProjectPermissionsWsRequest request, Paging paging) {
- Optional<WsProjectRef> project = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
+ Optional<ProjectWsRef> project = newOptionalWsProjectRef(request.getProjectId(), request.getProjectKey());
if (project.isPresent()) {
return singletonList(wsSupport.getRootComponentOrModule(dbSession, project.get()));
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.permission.ws;
-
-import com.google.common.base.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-import static org.sonar.server.ws.WsUtils.checkRequest;
-
-/**
- * Project identifiers from a WS request. Guaranties the project id and project key are not provided at the same time.
- */
-public class WsProjectRef {
- private static final String MSG_ID_OR_KEY_MUST_BE_PROVIDED = "Project id or project key can be provided, not both.";
- private final String uuid;
- private final String key;
-
- private WsProjectRef(@Nullable String uuid, @Nullable String key) {
- this.uuid = uuid;
- this.key = key;
- checkRequest(this.uuid != null ^ this.key != null, "Project id or project key can be provided, not both.");
- }
-
- public static Optional<WsProjectRef> newOptionalWsProjectRef(@Nullable String uuid, @Nullable String key) {
- if (uuid == null && key == null) {
- return Optional.absent();
- }
-
- return Optional.of(new WsProjectRef(uuid, key));
- }
-
- public static WsProjectRef newWsProjectRef(@Nullable String uuid, @Nullable String key) {
- checkRequest(uuid == null ^ key == null, MSG_ID_OR_KEY_MUST_BE_PROVIDED);
- return new WsProjectRef(uuid, key);
- }
-
- @CheckForNull
- public String uuid() {
- return this.uuid;
- }
-
- @CheckForNull
- public String key() {
- return this.key;
- }
-}
import static java.util.Collections.singletonList;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectParameters;
import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters;
-import static org.sonar.server.permission.ws.WsProjectRef.newWsProjectRef;
+import static org.sonar.server.permission.ws.ProjectWsRef.newWsProjectRef;
import static org.sonar.server.permission.ws.template.WsTemplateRef.newTemplateRef;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;