From: Julien Lancelot Date: Thu, 11 Sep 2014 16:08:45 +0000 (+0200) Subject: SONAR-5614 Create stub of WS /batch/upload_report X-Git-Tag: 5.0-RC1~1025 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ab1b694e5f1e83084bb4977adcaf4667d52c27ec;p=sonarqube.git SONAR-5614 Create stub of WS /batch/upload_report --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/BatchWs.java b/server/sonar-server/src/main/java/org/sonar/server/batch/BatchWs.java index 39f5fc8c695..99fa1ac21e0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/BatchWs.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/BatchWs.java @@ -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 index 00000000000..32846ef36e9 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/UploadReportAction.java @@ -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); + } + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java index 65834e8cd25..cb48dbeff87 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerComponents.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java index 1a497bb014a..1373d8468a6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/BatchWsTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalReferentialsActionTest.java index 4468e1b7f66..0d76bf44872 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalReferentialsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/GlobalReferentialsActionTest.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java index 67651e2e5f3..14185becbdf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java @@ -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