]> source.dussan.org Git - sonarqube.git/commitdiff
Drop OldRestoreAction (api/profiles/restore)
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Wed, 4 Oct 2017 14:32:50 +0000 (16:32 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 16 Oct 2017 14:03:55 +0000 (16:03 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java

index 1647effbf21331a438901f59659f00bc0dc3009f..046a9fa2f36785b62333963d1c0cc2949a203e54 100644 (file)
@@ -158,7 +158,6 @@ import org.sonar.server.qualityprofile.QProfileResetImpl;
 import org.sonar.server.qualityprofile.RuleActivator;
 import org.sonar.server.qualityprofile.RuleActivatorContextFactory;
 import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
-import org.sonar.server.qualityprofile.ws.OldRestoreAction;
 import org.sonar.server.qualityprofile.ws.ProfilesWs;
 import org.sonar.server.qualityprofile.ws.QProfilesWsModule;
 import org.sonar.server.root.ws.RootWsModule;
@@ -286,7 +285,6 @@ public class PlatformLevel4 extends PlatformLevel {
       AnnotationProfileParser.class,
       QProfileComparison.class,
       ProfilesWs.class,
-      OldRestoreAction.class,
       RuleActivator.class,
       QProfileExporters.class,
       RuleActivatorContextFactory.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
deleted file mode 100644 (file)
index fd026b2..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 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 java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import org.apache.commons.io.IOUtils;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Languages;
-import org.sonar.api.server.ws.Request;
-import org.sonar.api.server.ws.Response;
-import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.text.JsonWriter;
-import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.QProfileDto;
-import org.sonar.server.qualityprofile.BulkChangeResult;
-import org.sonar.server.qualityprofile.QProfileBackuper;
-import org.sonar.server.qualityprofile.QProfileRestoreSummary;
-import org.sonar.server.user.UserSession;
-import org.sonar.server.ws.WsAction;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_PROFILES;
-
-/**
- * @deprecated will be deleted once Orchestrator do not rely on this WS
- * It is duplicated to enable 
- */
-@Deprecated
-public class OldRestoreAction implements WsAction {
-
-  private static final String PARAM_BACKUP = "backup";
-
-  private final DbClient dbClient;
-  private final QProfileBackuper backuper;
-  private final Languages languages;
-  private final QProfileWsSupport qProfileWsSupport;
-  private final UserSession userSession;
-
-  public OldRestoreAction(DbClient dbClient, QProfileBackuper backuper, Languages languages, QProfileWsSupport qProfileWsSupport, UserSession userSession) {
-    this.dbClient = dbClient;
-    this.backuper = backuper;
-    this.languages = languages;
-    this.qProfileWsSupport = qProfileWsSupport;
-    this.userSession = userSession;
-  }
-
-  @Override
-  public void define(WebService.NewController controller) {
-    controller.createAction("restore")
-      .setSince("5.2")
-      .setDescription("Restore a quality profile using an XML file. The restored profile name is taken from the backup file, " +
-        "so if a profile with the same name and language already exists, it will be overwritten. " +
-        "Require Administer Quality Profiles permission.")
-      .setPost(true)
-      .setInternal(true)
-      .setHandler(this)
-      .createParam(PARAM_BACKUP)
-      .setDescription("A profile backup file in XML format, as generated by api/qualityprofiles/backup " +
-        "or the former api/profiles/backup.")
-      .setRequired(true);
-  }
-
-  @Override
-  public void handle(Request request, Response response) throws Exception {
-    userSession.checkLoggedIn();
-
-    InputStream backup = request.paramAsInputStream(PARAM_BACKUP);
-    checkArgument(backup != null, "A backup file must be provided");
-    InputStreamReader reader = null;
-
-    try (DbSession dbSession = dbClient.openSession(false)) {
-      OrganizationDto defaultOrg = qProfileWsSupport.getOrganizationByKey(dbSession, null);
-      userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, defaultOrg);
-      reader = new InputStreamReader(backup, StandardCharsets.UTF_8);
-      QProfileRestoreSummary result = backuper.restore(dbSession, reader, defaultOrg, null);
-      writeResponse(response.newJsonWriter(), result);
-    } finally {
-      IOUtils.closeQuietly(reader);
-      IOUtils.closeQuietly(backup);
-    }
-  }
-
-  private void writeResponse(JsonWriter json, QProfileRestoreSummary result) {
-    QProfileDto profile = result.getProfile();
-    String languageKey = profile.getLanguage();
-    Language language = languages.get(languageKey);
-
-    JsonWriter jsonProfile = json.beginObject().name("profile").beginObject();
-    jsonProfile
-      .prop("key", profile.getKee())
-      .prop("name", profile.getName())
-      .prop("language", languageKey)
-      .prop("isDefault", false)
-      .prop("isInherited", false);
-    if (language != null) {
-      jsonProfile.prop("languageName", language.getName());
-    }
-    jsonProfile.endObject();
-
-    BulkChangeResult ruleChanges = result.getRuleChanges();
-    json.prop("ruleSuccesses", ruleChanges.countSucceeded());
-    json.prop("ruleFailures", ruleChanges.countFailed());
-    json.endObject().close();
-  }
-}
index f013e1fd061e2431c225517c1f2e101021f75a0a..0531281299abf41cb14db224db4c30f83accdd84 100644 (file)
@@ -30,18 +30,11 @@ public class ProfilesWs implements WebService {
 
   public static final String API_ENDPOINT = "api/profiles";
 
-  private final OldRestoreAction restoreAction;
-
-  public ProfilesWs(OldRestoreAction restoreAction) {
-    this.restoreAction = restoreAction;
-  }
-
   @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");
-    restoreAction.define(controller);
     defineListAction(controller);
     defineIndexAction(controller);
     controller.done();
index 0be4f14388d8f2c16c5ea510cb097038f396cf9d..b70784cb709b1cbf0099368415bb603899618d8e 100644 (file)
@@ -21,16 +21,11 @@ package org.sonar.server.qualityprofile.ws;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.api.resources.Languages;
 import org.sonar.api.server.ws.WebService;
-import org.sonar.db.DbClient;
-import org.sonar.server.qualityprofile.QProfileBackuper;
-import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.RemovedWebServiceHandler;
 import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
 
 public class ProfilesWsTest {
 
@@ -38,8 +33,7 @@ public class ProfilesWsTest {
 
   @Before
   public void setUp() {
-    ws = new WsTester(new ProfilesWs(
-      new OldRestoreAction(mock(DbClient.class), mock(QProfileBackuper.class), mock(Languages.class), mock(QProfileWsSupport.class), mock(UserSession.class))));
+    ws = new WsTester(new ProfilesWs());
   }
 
   @Test
@@ -48,7 +42,7 @@ public class ProfilesWsTest {
     assertThat(controller).isNotNull();
     assertThat(controller.path()).isEqualTo("api/profiles");
     assertThat(controller.description()).isNotEmpty();
-    assertThat(controller.actions()).hasSize(3);
+    assertThat(controller.actions()).hasSize(2);
   }
 
   @Test