diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-10-04 16:32:50 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-10-16 16:03:55 +0200 |
commit | 5a3b71433f7f9b6a93f34de9ba0ea0941072020a (patch) | |
tree | bbc078118a8e1147df9409f77b1ce27cbd2f2a61 | |
parent | e7bd0a49dcbb5c67436402d9e32fda7d50ef874b (diff) | |
download | sonarqube-5a3b71433f7f9b6a93f34de9ba0ea0941072020a.tar.gz sonarqube-5a3b71433f7f9b6a93f34de9ba0ea0941072020a.zip |
Drop OldRestoreAction (api/profiles/restore)
4 files changed, 2 insertions, 143 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index 1647effbf21..046a9fa2f36 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -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 index fd026b29ba9..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java +++ /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(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java index f013e1fd061..0531281299a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java @@ -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(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java index 0be4f14388d..b70784cb709 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProfilesWsTest.java @@ -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 |