]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8134 Rename WsProjectRef to ProjectWsRef
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 13 Oct 2016 15:38:02 +0000 (17:38 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 16 Oct 2016 17:10:35 +0000 (19:10 +0200)
for consistency with org.sonar.server.usergroups.ws.ProjectId and ProjectWsRef

server/sonar-server/src/main/java/org/sonar/server/permission/ProjectId.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsAction.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/SearchProjectPermissionsDataLoader.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/WsProjectRef.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/ApplyTemplateAction.java

index a30387a11b52e842b54d188bbab3de791417c211..29639a44b38cfdce4c4ed63bb5e4e4fca713c962 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.server.permission;
 
 import javax.annotation.concurrent.Immutable;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.server.permission.ws.ProjectWsRef;
 
 import static java.util.Objects.requireNonNull;
 
@@ -28,7 +29,7 @@ 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 {
index 7fad14f64c08405f244f04a5824256e1d3daae86..239864fe868f9685b93af9a81330543feee9a91c 100644 (file)
@@ -64,7 +64,7 @@ public class PermissionWsSupport {
   /**
    * @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());
   }
@@ -73,13 +73,13 @@ public class PermissionWsSupport {
     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);
   }
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/ProjectWsRef.java
new file mode 100644 (file)
index 0000000..4006720
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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;
+  }
+}
index 953d74d6fe45f3625061910ea34550402d6f37de..685de7e4646c76afabe91032abb3146eedec14a0 100644 (file)
@@ -43,7 +43,7 @@ import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjec
 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;
@@ -114,7 +114,7 @@ public class SearchProjectPermissionsAction implements PermissionsWsAction {
   }
 
   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;
index 851c64cf664d6c8034644d3bf836f93418d44631..2b94d10cf2ddffff05c0c7df15c37033b4056b2b 100644 (file)
@@ -39,7 +39,7 @@ import static java.util.Collections.singletonList;
 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;
@@ -79,7 +79,7 @@ public class SearchProjectPermissionsDataLoader {
   }
 
   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()));
diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/ws/WsProjectRef.java b/server/sonar-server/src/main/java/org/sonar/server/permission/ws/WsProjectRef.java
deleted file mode 100644 (file)
index 68bd02c..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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;
-  }
-}
index bd72280a2684cf95c41c43d5d1be46da75844c90..3201990c0ba91dc2d015319578bf21db6929a6dd 100644 (file)
@@ -35,7 +35,7 @@ import org.sonarqube.ws.client.permission.ApplyTemplateWsRequest;
 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;