]> source.dussan.org Git - sonarqube.git/commitdiff
Remove unused QProfileOperations
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 7 Jul 2014 20:23:16 +0000 (22:23 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 8 Jul 2014 14:16:55 +0000 (16:16 +0200)
sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java [deleted file]
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectLookup.java
sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileProjectOperations.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfilesTest.java

index 3ecbb8bb0dc384c8316f1dd530bf2add13aa7e7b..d711892df8dc54bcd23274b1ca3f684196e304c8 100644 (file)
@@ -182,7 +182,6 @@ import org.sonar.server.qualityprofile.QProfileExporters;
 import org.sonar.server.qualityprofile.QProfileFactory;
 import org.sonar.server.qualityprofile.QProfileLoader;
 import org.sonar.server.qualityprofile.QProfileLookup;
-import org.sonar.server.qualityprofile.QProfileOperations;
 import org.sonar.server.qualityprofile.QProfileProjectLookup;
 import org.sonar.server.qualityprofile.QProfileProjectOperations;
 import org.sonar.server.qualityprofile.QProfileRepositoryExporter;
@@ -422,7 +421,6 @@ class ServerComponents {
     pico.addSingleton(AnnotationProfileParser.class);
     pico.addSingleton(QProfiles.class);
     pico.addSingleton(QProfileLookup.class);
-    pico.addSingleton(QProfileOperations.class);
     pico.addSingleton(QProfileProjectOperations.class);
     pico.addSingleton(QProfileProjectLookup.class);
     pico.addSingleton(QProfileRepositoryExporter.class);
diff --git a/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java b/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileOperations.java
deleted file mode 100644 (file)
index 872a144..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.core.permission.GlobalPermissions;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.MyBatis;
-import org.sonar.core.preview.PreviewCache;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.exceptions.BadRequestException;
-import org.sonar.server.user.UserSession;
-
-import java.util.Map;
-
-public class QProfileOperations implements ServerComponent {
-
-  public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
-
-  private final DbClient db;
-  private final QProfileRepositoryExporter exporter;
-  private final PreviewCache dryRunCache;
-
-  public QProfileOperations(DbClient db,
-    QProfileRepositoryExporter exporter, PreviewCache dryRunCache) {
-    this.db = db;
-    this.exporter = exporter;
-    this.dryRunCache = dryRunCache;
-  }
-
-  public QProfileResult newProfile(String name, String language, Map<String, String> xmlProfilesByPlugin, UserSession userSession) {
-    DbSession session = db.openSession(false);
-    try {
-      QProfile profile = newProfile(name, language, true, userSession, session);
-
-      QProfileResult result = new QProfileResult();
-      result.setProfile(profile);
-
-      for (Map.Entry<String, String> entry : xmlProfilesByPlugin.entrySet()) {
-        result.add(exporter.importXml(profile, entry.getKey(), entry.getValue(), session));
-      }
-      dryRunCache.reportGlobalModification(session);
-      session.commit();
-      return result;
-    } finally {
-      MyBatis.closeQuietly(session);
-    }
-  }
-
-  private QProfile newProfile(String name, String language, boolean failIfAlreadyExists, UserSession userSession, DbSession session) {
-    checkPermission(userSession);
-    if (failIfAlreadyExists) {
-      checkNotAlreadyExists(name, language, session);
-    }
-    QualityProfileDto dto = new QualityProfileDto().setName(name).setLanguage(language);
-    db.qualityProfileDao().insert(session, dto);
-    return QProfile.from(dto);
-  }
-
-  private void checkPermission(UserSession userSession) {
-    userSession.checkLoggedIn();
-    userSession.checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
-  }
-
-  private void checkNotAlreadyExists(String name, String language, DbSession session) {
-    if (db.qualityProfileDao().getByNameAndLanguage(name, language, session) != null) {
-      throw new BadRequestException("quality_profiles.profile_x_already_exists", name);
-    }
-  }
-
-}
index 2f71fa67051ba2454a32b91101ac1c8f298de91d..b61a4d9224c75a9117ea877c8fc63ab8c2c61404 100644 (file)
@@ -39,6 +39,7 @@ import java.util.Map;
 
 public class QProfileProjectLookup implements ServerComponent {
 
+  public static final String PROFILE_PROPERTY_PREFIX = "sonar.profile.";
   private final DbClient db;
 
   public QProfileProjectLookup(DbClient db) {
@@ -52,7 +53,7 @@ public class QProfileProjectLookup implements ServerComponent {
       QProfileValidations.checkProfileIsNotNull(qualityProfile);
       Map<String, Component> componentsByKeys = Maps.newHashMap();
       for (Component component : db.qualityProfileDao().selectProjects(
-        qualityProfile.getName(), QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), session
+        qualityProfile.getName(), PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), session
         )) {
         componentsByKeys.put(component.key(), component);
       }
@@ -73,12 +74,12 @@ public class QProfileProjectLookup implements ServerComponent {
   }
 
   public int countProjects(QProfile profile) {
-    return db.qualityProfileDao().countProjects(profile.name(), QProfileOperations.PROFILE_PROPERTY_PREFIX + profile.language());
+    return db.qualityProfileDao().countProjects(profile.name(), PROFILE_PROPERTY_PREFIX + profile.language());
   }
 
   @CheckForNull
   public QProfile findProfileByProjectAndLanguage(long projectId, String language) {
-    QualityProfileDto dto = db.qualityProfileDao().getByProjectAndLanguage(projectId, language, QProfileOperations.PROFILE_PROPERTY_PREFIX + language);
+    QualityProfileDto dto = db.qualityProfileDao().getByProjectAndLanguage(projectId, language, PROFILE_PROPERTY_PREFIX + language);
     if (dto != null) {
       return QProfile.from(dto);
     }
index 70cc10e4016f3430559d3f4551d9a1970f6b5595..f1e694297ca0e96bf436dd66043876d2a4a96640 100644 (file)
@@ -48,7 +48,7 @@ public class QProfileProjectOperations implements ServerComponent {
       QualityProfileDto qualityProfile = findNotNull(profileId, session);
 
       db.propertiesDao().setProperty(new PropertyDto().setKey(
-        QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage()).setValue(qualityProfile.getName()).setResourceId(project.getId()), session);
+        QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage()).setValue(qualityProfile.getName()).setResourceId(project.getId()), session);
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
@@ -62,7 +62,7 @@ public class QProfileProjectOperations implements ServerComponent {
       ComponentDto project = (ComponentDto) findProjectNotNull(projectId, session);
       QualityProfileDto qualityProfile = findNotNull(profileId, session);
 
-      db.propertiesDao().deleteProjectProperty(QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), project.getId(), session);
+      db.propertiesDao().deleteProjectProperty(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), project.getId(), session);
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
@@ -75,7 +75,7 @@ public class QProfileProjectOperations implements ServerComponent {
     try {
       ComponentDto project = (ComponentDto) findProjectNotNull(projectId, session);
 
-      db.propertiesDao().deleteProjectProperty(QProfileOperations.PROFILE_PROPERTY_PREFIX + language, project.getId(), session);
+      db.propertiesDao().deleteProjectProperty(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + language, project.getId(), session);
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
@@ -87,7 +87,7 @@ public class QProfileProjectOperations implements ServerComponent {
     DbSession session = db.openSession(false);
     try {
       QualityProfileDto qualityProfile = findNotNull(profileId, session);
-      db.propertiesDao().deleteProjectProperties(QProfileOperations.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), qualityProfile.getName(), session);
+      db.propertiesDao().deleteProjectProperties(QProfileProjectLookup.PROFILE_PROPERTY_PREFIX + qualityProfile.getLanguage(), qualityProfile.getName(), session);
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
index 40719dc03c38b32b2a1e2d960bc853d5d2fd5d9e..59ecedf9321cd717aac36d543a942a5ff7671439 100644 (file)
@@ -43,9 +43,6 @@ public class QProfilesTest {
   @Mock
   QProfileLookup profileLookup;
 
-  @Mock
-  QProfileOperations profileOperations;
-
   QProfiles qProfiles;
 
   @Before