]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jul 2015 09:38:32 +0000 (11:38 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 15 Jul 2015 09:38:32 +0000 (11:38 +0200)
server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/MetricsAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/custom/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/DeleteAction.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java
sonar-db/src/main/java/org/sonar/core/properties/PropertyDto.java

index 7ce1e6ef1732ee0bf633a5370f11e8a96fb10e1b..5acd0f73da3f92c932ce94639b5879b7eb946833 100644 (file)
@@ -37,7 +37,7 @@ public class ComponentFinder {
     this.dbClient = dbClient;
   }
 
-  public ComponentDto getByKeyOrUuid(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey) {
+  public ComponentDto getByUuidOrKey(DbSession dbSession, @Nullable String componentUuid, @Nullable String componentKey) {
     checkArgument(componentUuid != null ^ componentKey != null, "The component key or the component id must be provided, not both.");
 
     if (componentUuid != null) {
index 4b358482bf35579477aa3054dc9330369d176732..085898cb64ec0c87096e388eef4e69339656df4d 100644 (file)
@@ -97,7 +97,6 @@ public class ComponentService {
     }
   }
 
-  @CheckForNull
   public Optional<ComponentDto> getByUuid(String uuid) {
     DbSession session = dbClient.openSession(false);
     try {
index c9d0bcbcb3d81c59d040528875ac9fa5da0c9e34..0eac871bb7ae6de3206f100712f0adfdd7c3ba00 100644 (file)
@@ -85,7 +85,7 @@ public class ShowAction implements RequestHandler {
 
     DbSession session = dbClient.openSession(false);
     try {
-      ComponentDto component = componentFinder.getByKeyOrUuid(session, fileUuid, fileKey);
+      ComponentDto component = componentFinder.getByUuidOrKey(session, fileUuid, fileKey);
       String componentKey = component.key();
       userSession.checkComponentPermission(UserRole.CODEVIEWER, componentKey);
       JsonWriter json = response.newJsonWriter().beginObject();
index 149b45b6c2747c3f70f9c702e45b45c64e51fa1b..cb331120bde48d84fb1b7025c5ecde980dd92266 100644 (file)
@@ -115,7 +115,7 @@ public class CreateAction implements CustomMeasuresWsAction {
     long now = system.now();
 
     try {
-      ComponentDto component = componentFinder.getByKeyOrUuid(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
+      ComponentDto component = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
       MetricDto metric = searchMetric(dbSession, request);
       checkPermissions(userSession, component);
       checkIsProjectOrModule(component);
index 97725bba3dbd4c1adf082c3ba467dd17e0be7a08..cb757ebc1d88ec02126eac9419ef73e5edc54a5d 100644 (file)
@@ -77,7 +77,7 @@ public class MetricsAction implements CustomMeasuresWsAction {
     DbSession dbSession = dbClient.openSession(false);
 
     try {
-      ComponentDto project = componentFinder.getByKeyOrUuid(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, request.param(CreateAction.PARAM_PROJECT_ID), request.param(CreateAction.PARAM_PROJECT_KEY));
       checkPermissions(userSession, project);
       List<MetricDto> metrics = searchMetrics(dbSession, project);
 
index 07034962fabb4fb9ef6bb4a41f0477a36aa18500..4f1ce7164190dbc271ca3de882ab27cf5e020885 100644 (file)
@@ -100,7 +100,7 @@ public class SearchAction implements CustomMeasuresWsAction {
 
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto project = componentFinder.getByKeyOrUuid(dbSession, projectUuid, projectKey);
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, projectUuid, projectKey);
       checkPermissions(userSession, project);
       Long lastAnalysisDateMs = searchLastSnapshot(dbSession, project);
       List<CustomMeasureDto> customMeasures = searchCustomMeasures(dbSession, project, searchOptions);
index ad3dd94301086ce37e19b96152fdbf393d2d62e9..3f65691fc2c7dc80185be9730d72c69855b8fea7 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.server.project.ws;
 
-import com.google.common.base.Optional;
 import java.util.Arrays;
 import javax.annotation.Nullable;
 import org.sonar.api.server.ws.Request;
@@ -33,7 +32,7 @@ import org.sonar.db.DbSession;
 import org.sonar.db.MyBatis;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.component.ComponentCleanerService;
-import org.sonar.server.exceptions.NotFoundException;
+import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.user.UserSession;
 
 public class DeleteAction implements ProjectsWsAction {
@@ -43,11 +42,13 @@ public class DeleteAction implements ProjectsWsAction {
   public static final String PARAM_KEY = "key";
 
   private final ComponentCleanerService componentCleanerService;
+  private final ComponentFinder componentFinder;
   private final DbClient dbClient;
   private final UserSession userSession;
 
-  public DeleteAction(ComponentCleanerService componentCleanerService, DbClient dbClient, UserSession userSession) {
+  public DeleteAction(ComponentCleanerService componentCleanerService, ComponentFinder componentFinder, DbClient dbClient, UserSession userSession) {
     this.componentCleanerService = componentCleanerService;
+    this.componentFinder = componentFinder;
     this.dbClient = dbClient;
     this.userSession = userSession;
   }
@@ -80,7 +81,7 @@ public class DeleteAction implements ProjectsWsAction {
 
     DbSession dbSession = dbClient.openSession(false);
     try {
-      ComponentDto project = getProject(dbSession, uuid, key);
+      ComponentDto project = componentFinder.getByUuidOrKey(dbSession, uuid, key);
       componentCleanerService.delete(dbSession, Arrays.asList(project));
     } finally {
       MyBatis.closeQuietly(dbSession);
@@ -103,20 +104,4 @@ public class DeleteAction implements ProjectsWsAction {
     return uuid != null && !userSession.hasProjectPermissionByUuid(UserRole.ADMIN, uuid) && !userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN);
   }
 
-  private ComponentDto getProject(DbSession session, @Nullable String uuid, @Nullable String key) {
-    if (key == null && uuid != null) {
-      Optional<ComponentDto> componentDto = dbClient.componentDao().selectByUuid(session, uuid);
-      if (!componentDto.isPresent()) {
-        throw new NotFoundException(String.format("Component with uuid '%s' not found", uuid));
-      }
-      return componentDto.get();
-    } else if (uuid == null && key != null) {
-      Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKey(session, key);
-      if (!componentDto.isPresent()) {
-        throw new NotFoundException(String.format("Component with key '%s' not found", key));
-      }
-      return componentDto.get();
-    }
-    throw new IllegalArgumentException("Id or key must be provided");
-  }
 }
index 8af651d06a5564a1a9b4957d91e5aacab5c199e0..0ed28ff6ca669a8467d68dd456aef1e973da4279 100644 (file)
@@ -124,6 +124,7 @@ public class DeleteActionTest {
           new TestIndexer(dbClient, es.client()),
           mockResourceTypes,
           new ComponentFinder(dbClient)),
+        new ComponentFinder(dbClient),
         dbClient,
         userSessionRule)));
     userSessionRule.login("login").setGlobalPermissions(UserRole.ADMIN);
index 57b2da5716f441fb5d381dfc9c2389c621e43a16..1a20d8643a46e101d79872b8a2dce472981af013 100644 (file)
@@ -28,11 +28,13 @@ package org.sonar.core.properties;
 @Deprecated
 public class PropertyDto extends org.sonar.db.property.PropertyDto {
 
+  @Override
   public PropertyDto setKey(String key) {
     super.setKey(key);
     return this;
   }
 
+  @Override
   public PropertyDto setValue(String value) {
     super.setValue(value);
     return this;