]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5614 Create stub of WS /batch/upload_report
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 11 Sep 2014 16:08:45 +0000 (18:08 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 11 Sep 2014 16:08:45 +0000 (18:08 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/BatchWs.java
server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java
server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/GlobalReferentialsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java

index 39f5fc8c6956cbb2bac8879f99af8e3913575e04..99fa1ac21e0bc95c75d414f0ed0728a3f46df1ca 100644 (file)
@@ -33,11 +33,14 @@ public class BatchWs implements WebService {
   private final BatchIndex batchIndex;
   private final GlobalReferentialsAction globalReferentialsAction;
   private final ProjectReferentialsAction projectReferentialsAction;
+  private final UploadReportAction uploadReportAction;
 
-  public BatchWs(BatchIndex batchIndex, GlobalReferentialsAction globalReferentialsAction, ProjectReferentialsAction projectReferentialsAction) {
+  public BatchWs(BatchIndex batchIndex, GlobalReferentialsAction globalReferentialsAction, ProjectReferentialsAction projectReferentialsAction,
+                 UploadReportAction uploadReportAction) {
     this.batchIndex = batchIndex;
     this.globalReferentialsAction = globalReferentialsAction;
     this.projectReferentialsAction = projectReferentialsAction;
+    this.uploadReportAction = uploadReportAction;
   }
 
   @Override
@@ -50,6 +53,7 @@ public class BatchWs implements WebService {
     defineFileAction(controller);
     globalReferentialsAction.define(controller);
     projectReferentialsAction.define(controller);
+    uploadReportAction.define(controller);
 
     controller.done();
   }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java
new file mode 100644 (file)
index 0000000..32846ef
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.batch;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.RequestHandler;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.MyBatis;
+import org.sonar.server.db.DbClient;
+
+public class UploadReportAction implements RequestHandler {
+
+  private static final String PARAM_PROJECT = "project";
+  private static final String PARAM_FIRST_ANALYSIS = "firstAnalysis";
+
+  private final DbClient dbClient;
+
+  public UploadReportAction(DbClient dbClient) {
+    this.dbClient = dbClient;
+  }
+
+  void define(WebService.NewController controller) {
+    WebService.NewAction action = controller.createAction("upload_report")
+      .setDescription("Update analysis report")
+      .setSince("5.0")
+      .setPost(true)
+      .setInternal(true)
+      .setHandler(this);
+
+    action
+      .createParam(PARAM_PROJECT)
+      .setRequired(true)
+      .setDescription("Project key")
+      .setExampleValue("org.codehaus.sonar:sonar");
+
+    action
+      .createParam(PARAM_FIRST_ANALYSIS)
+      .setDescription("Is it the first analysis of this project ?")
+      .setDefaultValue(false)
+      .setBooleanPossibleValues();
+  }
+
+  @Override
+  public void handle(Request request, Response response) throws Exception {
+    DbSession session = dbClient.openSession(false);
+    try {
+      // TODO
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+  }
+
+}
index 65834e8cd251a1132ff6e72a7fc85b12a55f06e1..cb48dbeff87e2a3a14007b2dd6a951d9c99ce62c 100644 (file)
@@ -77,10 +77,7 @@ import org.sonar.server.activity.index.ActivityNormalizer;
 import org.sonar.server.activity.ws.ActivitiesWebService;
 import org.sonar.server.activity.ws.ActivityMapping;
 import org.sonar.server.authentication.ws.AuthenticationWs;
-import org.sonar.server.batch.BatchIndex;
-import org.sonar.server.batch.BatchWs;
-import org.sonar.server.batch.GlobalReferentialsAction;
-import org.sonar.server.batch.ProjectReferentialsAction;
+import org.sonar.server.batch.*;
 import org.sonar.server.charts.ChartFactory;
 import org.sonar.server.component.DefaultComponentFinder;
 import org.sonar.server.component.DefaultRubyComponentService;
@@ -322,6 +319,7 @@ class ServerComponents {
     pico.addSingleton(BatchIndex.class);
     pico.addSingleton(GlobalReferentialsAction.class);
     pico.addSingleton(ProjectReferentialsAction.class);
+    pico.addSingleton(UploadReportAction.class);
     pico.addSingleton(BatchWs.class);
 
     // update center
index 1a497bb014aff22ef0c6d358147e49d33feb0d0a..1373d8468a691f0b393a48e5ff7a287f46f9abdf 100644 (file)
@@ -61,7 +61,9 @@ public class BatchWsTest {
   public void before() throws IOException {
     tester = new WsTester(new BatchWs(batchIndex,
       new GlobalReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class)),
-      new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class), mock(Languages.class))));
+      new ProjectReferentialsAction(mock(DbClient.class), mock(PropertiesDao.class), mock(QProfileFactory.class), mock(QProfileLoader.class), mock(RuleService.class),
+        mock(Languages.class)),
+      new UploadReportAction(mock(DbClient.class))));
   }
 
   @Test
index 4468e1b7f66ed125518b1c728a9fddf828077619..0d76bf4487275b9961bbdb90c04af244dd890405 100644 (file)
@@ -59,7 +59,7 @@ public class GlobalReferentialsActionTest {
     when(dbClient.openSession(false)).thenReturn(session);
     when(dbClient.metricDao()).thenReturn(metricDao);
 
-    tester = new WsTester(new BatchWs(mock(BatchIndex.class), new GlobalReferentialsAction(dbClient, propertiesDao), mock(ProjectReferentialsAction.class)));
+    tester = new WsTester(new BatchWs(mock(BatchIndex.class), new GlobalReferentialsAction(dbClient, propertiesDao), mock(ProjectReferentialsAction.class), mock(UploadReportAction.class)));
   }
 
   @Test
index 67651e2e5f32cd1001c51e2ac92fded6b8b6596f..14185becbdf5597054d4678444c4cc603ce4e637 100644 (file)
@@ -111,7 +111,7 @@ public class ProjectReferentialsActionTest {
       );
 
     tester = new WsTester(new BatchWs(mock(BatchIndex.class), mock(GlobalReferentialsAction.class),
-      new ProjectReferentialsAction(dbClient, propertiesDao, qProfileFactory, qProfileLoader, ruleService, languages)));
+      new ProjectReferentialsAction(dbClient, propertiesDao, qProfileFactory, qProfileLoader, ruleService, languages), mock(UploadReportAction.class)));
   }
 
   @Test