]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6314 Create Java WS api/profiles/restore used in Orchestrator
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 2 Oct 2015 16:24:34 +0000 (18:24 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 5 Oct 2015 07:37:18 +0000 (09:37 +0200)
it/it-tests/src/test/java/administration/suite/administration/ProjectAdministrationTest.java
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 [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProfilesWs.java [new file with mode: 0644]

index a9565acabb7de4a113e6f368af81692eba401962..0116963a3bc1680e5bdd5396f04f60bf378bc6b8 100644 (file)
@@ -120,8 +120,8 @@ public class ProjectAdministrationTest {
         "permission", "admin");
 
       new SeleneseTest(
-        Selenese.builder().setHtmlTestsInClasspath("project-deletion", "/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html").build()
-      ).runOn(orchestrator);
+        Selenese.builder().setHtmlTestsInClasspath("project-deletion", "/administration/suite/ProjectAdministrationTest/project-deletion/project-deletion.html").build())
+        .runOn(orchestrator);
     } finally {
       wsClient.userClient().deactivate(projectAdminUser);
     }
index de062342146c2fda5566c9e12355f571c8c82278..6f9a1fe66382c668266d9b6e4871fb9ec4097c9a 100644 (file)
@@ -234,6 +234,8 @@ import org.sonar.server.qualityprofile.ws.ExportAction;
 import org.sonar.server.qualityprofile.ws.ExportersAction;
 import org.sonar.server.qualityprofile.ws.ImportersAction;
 import org.sonar.server.qualityprofile.ws.InheritanceAction;
+import org.sonar.server.qualityprofile.ws.OldRestoreAction;
+import org.sonar.server.qualityprofile.ws.ProfilesWs;
 import org.sonar.server.qualityprofile.ws.ProjectAssociationActions;
 import org.sonar.server.qualityprofile.ws.ProjectsAction;
 import org.sonar.server.qualityprofile.ws.QProfilesWs;
@@ -334,16 +336,16 @@ public class PlatformLevel4 extends PlatformLevel {
       IndexDefinitions.class,
       IndexCreator.class,
 
-    // Activity
+      // Activity
       ActivityService.class,
       ActivityIndexDefinition.class,
       ActivityIndexer.class,
       ActivityIndex.class,
 
-    // batch
+      // batch
       BatchWsModule.class,
 
-    // Dashboard
+      // Dashboard
       DashboardsWs.class,
       org.sonar.server.dashboard.ws.ShowAction.class,
       ProjectDefaultDashboard.class,
@@ -381,12 +383,12 @@ public class PlatformLevel4 extends PlatformLevel {
       ProjectIssueFilterWidget.class,
       IssueTagCloudWidget.class,
 
-    // update center
+      // update center
       UpdateCenterClient.class,
       UpdateCenterMatrixFactory.class,
       UpdateCenterWs.class,
 
-    // quality profile
+      // quality profile
       XMLProfileParser.class,
       XMLProfileSerializer.class,
       AnnotationProfileParser.class,
@@ -415,6 +417,8 @@ public class PlatformLevel4 extends PlatformLevel {
       ExportAction.class,
       ExportersAction.class,
       QProfilesWs.class,
+      ProfilesWs.class,
+      OldRestoreAction.class,
       RuleActivationActions.class,
       BulkRuleActivationActions.class,
       ProjectAssociationActions.class,
@@ -429,7 +433,7 @@ public class PlatformLevel4 extends PlatformLevel {
       QProfileReset.class,
       RubyQProfileActivityService.class,
 
-    // rule
+      // rule
       AnnotationRuleParser.class,
       XMLRuleParser.class,
       DefaultRuleFinder.class,
@@ -457,17 +461,17 @@ public class PlatformLevel4 extends PlatformLevel {
       RepositoriesAction.class,
       org.sonar.server.rule.ws.AppAction.class,
 
-    // languages
+      // languages
       Languages.class,
       LanguageWs.class,
       org.sonar.server.language.ws.ListAction.class,
 
-    // activity
+      // activity
       ActivitiesWs.class,
       org.sonar.server.activity.ws.SearchAction.class,
       ActivityMapping.class,
 
-    // measure
+      // measure
       MeasureFilterFactory.class,
       MeasureFilterExecutor.class,
       MeasureFilterEngine.class,
@@ -479,14 +483,14 @@ public class PlatformLevel4 extends PlatformLevel {
       DefaultMetricFinder.class,
       TimeMachineWs.class,
 
-    // quality gates
+      // quality gates
       QualityGateDao.class,
       QualityGateConditionDao.class,
       QualityGates.class,
       ProjectQgateAssociationDao.class,
       QgateProjectFinder.class,
 
-    org.sonar.server.qualitygate.ws.ListAction.class,
+      org.sonar.server.qualitygate.ws.ListAction.class,
       org.sonar.server.qualitygate.ws.SearchAction.class,
       org.sonar.server.qualitygate.ws.ShowAction.class,
       org.sonar.server.qualitygate.ws.CreateAction.class,
@@ -503,17 +507,17 @@ public class PlatformLevel4 extends PlatformLevel {
       org.sonar.server.qualitygate.ws.AppAction.class,
       QGatesWs.class,
 
-    // web services
+      // web services
       WebServiceEngine.class,
       ListingWs.class,
 
-    // localization
+      // localization
       L10nWs.class,
 
-    // authentication
+      // authentication
       AuthenticationWs.class,
 
-    // users
+      // users
       SecurityRealmFactory.class,
       DeprecatedUserFinder.class,
       NewUserNotifier.class,
@@ -535,19 +539,19 @@ public class PlatformLevel4 extends PlatformLevel {
       UserIndex.class,
       UserUpdater.class,
 
-    // groups
+      // groups
       GroupMembershipService.class,
       GroupMembershipFinder.class,
       UserGroupsModule.class,
 
-    // permissions
+      // permissions
       PermissionRepository.class,
       PermissionService.class,
       PermissionUpdater.class,
       PermissionFinder.class,
       PermissionsWsModule.class,
 
-    // components
+      // components
       ProjectsWsModule.class,
       ComponentsWsModule.class,
       DefaultComponentFinder.class,
@@ -558,12 +562,12 @@ public class PlatformLevel4 extends PlatformLevel {
       NewAlerts.newMetadata(),
       ComponentCleanerService.class,
 
-    // views
+      // views
       ViewIndexDefinition.class,
       ViewIndexer.class,
       ViewIndex.class,
 
-    // issues
+      // issues
       IssueIndexDefinition.class,
       IssueIndexer.class,
       IssueAuthorizationIndexer.class,
@@ -597,13 +601,13 @@ public class PlatformLevel4 extends PlatformLevel {
       EmailNotificationChannel.class,
       AlertsEmailTemplate.class,
 
-    IssueFilterWsModule.class,
+      IssueFilterWsModule.class,
 
-    // action plan
+      // action plan
       ActionPlanWs.class,
       ActionPlanService.class,
 
-    // issues actions
+      // issues actions
       AssignAction.class,
       PlanAction.class,
       SetSeverityAction.class,
@@ -612,7 +616,7 @@ public class PlatformLevel4 extends PlatformLevel {
       AddTagsAction.class,
       RemoveTagsAction.class,
 
-    // technical debt
+      // technical debt
       DebtModelService.class,
       DebtModelOperations.class,
       DebtModelLookup.class,
@@ -622,7 +626,7 @@ public class PlatformLevel4 extends PlatformLevel {
       DebtRulesXMLImporter.class,
       DebtCharacteristicsXMLImporter.class,
 
-    // source
+      // source
       HtmlSourceDecorator.class,
       SourceService.class,
       SourcesWs.class,
@@ -633,23 +637,23 @@ public class PlatformLevel4 extends PlatformLevel {
       IndexAction.class,
       ScmAction.class,
 
-    // Duplications
+      // Duplications
       DuplicationsParser.class,
       DuplicationsWs.class,
       DuplicationsJsonWriter.class,
       org.sonar.server.duplication.ws.ShowAction.class,
 
-    // text
+      // text
       MacroInterpreter.class,
       RubyTextService.class,
 
-    // Notifications
+      // Notifications
       EmailSettings.class,
       NotificationService.class,
       NotificationCenter.class,
       DefaultNotificationManager.class,
 
-    // Tests
+      // Tests
       CoverageService.class,
       TestsWs.class,
       CoveredFilesAction.class,
@@ -658,12 +662,12 @@ public class PlatformLevel4 extends PlatformLevel {
       TestIndex.class,
       TestIndexer.class,
 
-    // Properties
+      // Properties
       PropertiesWs.class,
 
-    TypeValidationModule.class,
+      TypeValidationModule.class,
 
-    // System
+      // System
       RestartAction.class,
       InfoAction.class,
       UpgradesAction.class,
@@ -678,7 +682,7 @@ public class PlatformLevel4 extends PlatformLevel {
       MigrateDbAction.class,
       DbMigrationStatusAction.class,
 
-    // Plugins WS
+      // Plugins WS
       PluginWSCommons.class,
       PluginUpdateAggregator.class,
       InstalledAction.class,
@@ -691,18 +695,18 @@ public class PlatformLevel4 extends PlatformLevel {
       CancelAllAction.class,
       PluginsWs.class,
 
-    // Compute engine
+      // Compute engine
       CeModule.class,
       CeQueueModule.class,
       CeTaskProcessorModule.class,
       CeWsModule.class,
       ReportProcessingModule.class,
 
-    // Views plugin
+      // Views plugin
       ViewsBootstrap.class,
       ViewsStopper.class,
 
-    // UI
+      // UI
       GlobalNavigationAction.class,
       SettingsNavigationAction.class,
       ComponentNavigationAction.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
new file mode 100644 (file)
index 0000000..c47bf51
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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.ws;
+
+import com.google.common.base.Preconditions;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.IOUtils;
+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.core.permission.GlobalPermissions;
+import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.qualityprofile.BulkChangeResult;
+import org.sonar.server.qualityprofile.QProfileBackuper;
+import org.sonar.server.user.UserSession;
+import org.sonar.server.ws.WsAction;
+
+@Deprecated
+/**
+ * @deprecated will be deleted once Orchestrator do not rely on this WS
+ * It is duplicated to enable 
+ */
+public class OldRestoreAction implements WsAction {
+
+  private static final String PARAM_BACKUP = "backup";
+  private final QProfileBackuper backuper;
+  private final Languages languages;
+  private final UserSession userSession;
+
+  public OldRestoreAction(QProfileBackuper backuper, Languages languages, UserSession userSession) {
+    this.backuper = backuper;
+    this.languages = languages;
+    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.")
+      .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().checkGlobalPermission(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+    InputStream backup = request.paramAsInputStream(PARAM_BACKUP);
+    InputStreamReader reader = null;
+
+    try {
+      Preconditions.checkArgument(backup != null, "A backup file must be provided");
+      reader = new InputStreamReader(backup, StandardCharsets.UTF_8);
+      BulkChangeResult result = backuper.restore(reader, null);
+      writeResponse(response.newJsonWriter(), result);
+    } finally {
+      IOUtils.closeQuietly(reader);
+      IOUtils.closeQuietly(backup);
+    }
+  }
+
+  private void writeResponse(JsonWriter json, BulkChangeResult result) {
+    QualityProfileDto profile = result.profile();
+    if (profile != null) {
+      String language = profile.getLanguage();
+      json.beginObject().name("profile").beginObject()
+        .prop("key", profile.getKey())
+        .prop("name", profile.getName())
+        .prop("language", language)
+        .prop("languageName", languages.get(profile.getLanguage()).getName())
+        .prop("isDefault", false)
+        .prop("isInherited", false)
+        .endObject();
+    }
+    json.prop("ruleSuccesses", result.countSucceeded());
+    json.prop("ruleFailures", result.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
new file mode 100644 (file)
index 0000000..3ec2957
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.ws;
+
+import org.sonar.api.server.ws.WebService;
+
+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("Old Quality Profiles")
+      .setSince("4.4");
+
+    restoreAction.define(controller);
+    controller.done();
+  }
+}