From 48ff995f344b7a1819e74236680f5e05a0b0870e Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 19 Sep 2014 18:58:38 +0200 Subject: [PATCH] SONAR-5623 - datamodel and dto creation for the analysis report --- .../computation/db/AnalysisReportDao.java | 77 +++++++++++++++++++ .../server/computation/db/package-info.java | 24 ++++++ .../AnalysisReportDaoTest/insert-result.xml | 29 +++++++ .../db/migrate/702_create_analysis_reports.rb | 38 +++++++++ .../computation/db/AnalysisReportDto.java | 77 +++++++++++++++++++ .../computation/db/AnalysisReportMapper.java | 27 +++++++ .../core/computation/db/package-info.java | 24 ++++++ .../sonar/core/computation/package-info.java | 24 ++++++ .../core/persistence/DatabaseVersion.java | 3 +- .../org/sonar/core/persistence/MyBatis.java | 6 +- .../computation/db/AnalysisReportMapper.xml | 12 +++ .../org/sonar/core/persistence/rows-h2.sql | 1 + .../org/sonar/core/persistence/schema-h2.ddl | 13 +++- 13 files changed, 352 insertions(+), 3 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb create mode 100644 sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java create mode 100644 sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java create mode 100644 sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java create mode 100644 sonar-core/src/main/java/org/sonar/core/computation/package-info.java create mode 100644 sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java new file mode 100644 index 00000000000..f22b172f8ea --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java @@ -0,0 +1,77 @@ +/* + * 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.computation.db; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import org.sonar.api.utils.System2; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.computation.db.AnalysisReportMapper; +import org.sonar.core.issue.db.IssueDto; +import org.sonar.core.issue.db.IssueMapper; +import org.sonar.core.persistence.DaoComponent; +import org.sonar.core.persistence.DbSession; +import org.sonar.server.db.BaseDao; +import org.sonar.server.search.IndexDefinition; + +import java.util.Date; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class AnalysisReportDao extends BaseDao implements DaoComponent { + + public AnalysisReportDao() { + this(System2.INSTANCE); + } + + @VisibleForTesting + public AnalysisReportDao(System2 system) { + super(AnalysisReportMapper.class, system); + } + + @Override + protected AnalysisReportDto doGetNullableByKey(DbSession session, String key) { + throw new UnsupportedOperationException(); + } + + @Override + protected AnalysisReportDto doUpdate(DbSession session, AnalysisReportDto issue) { + throw new UnsupportedOperationException(); + } + + @Override + protected AnalysisReportDto doInsert(DbSession session, AnalysisReportDto report) { + checkNotNull(report.getProjectKey(), "Cannot insert Report with no project key!"); + mapper(session).insert(report); + return report; + } + + @Override + protected String getSynchronizationStatementName() { + throw new UnsupportedOperationException(); + } + + @Override + protected Map getSynchronizationParams(Date date, Map params) { + throw new UnsupportedOperationException(); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java new file mode 100644 index 00000000000..d34d4927eb3 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/db/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.server.computation.db; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml new file mode 100644 index 00000000000..40a65358922 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml @@ -0,0 +1,29 @@ + + + + + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb new file mode 100644 index 00000000000..424095738a5 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb @@ -0,0 +1,38 @@ +# +# 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. +# +# +# SonarQube 5.0 +# SONAR-5624 +# +class CreateAnalysisReports < ActiveRecord::Migration + + def self.up + create_table :analysis_reports do |t| + t.column :project_key, :string, :limit => 400, :null => false + t.column :report_status, :string, :limit => 20, :null => false + t.column :report_data, :text, :null => true + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + add_index :analysis_reports, ['project_key'], :name => 'analysis_reports_project_key', :unique => true + end + +end + diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java new file mode 100644 index 00000000000..7af44d41e5c --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java @@ -0,0 +1,77 @@ +/* + * 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.core.computation.db; + +import org.sonar.core.persistence.Dto; + +import javax.annotation.Nullable; + +/** + * since 5.0 + */ +public class AnalysisReportDto extends Dto { + + private Long id; + private String projectKey; + private String status; + private String data; + + public String getProjectKey() { + return projectKey; + } + + public AnalysisReportDto setProjectKey(String projectKey) { + this.projectKey = projectKey; + return this; + } + + public String getStatus() { + return status; + } + + public AnalysisReportDto setStatus(String status) { + this.status = status; + return this; + } + + public String getData() { + return data; + } + + public AnalysisReportDto setData(@Nullable String data) { + this.data = data; + return this; + } + + + @Override + public String getKey() { + return getProjectKey(); + } + + public Long getId() { + return id; + } + + public AnalysisReportDto setId(Long id) { + this.id = id; + return this; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java new file mode 100644 index 00000000000..8f5983676c1 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java @@ -0,0 +1,27 @@ +/* + * 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.core.computation.db; + +/** + * since 5.0 + */ +public interface AnalysisReportMapper { + void insert(AnalysisReportDto report); +} diff --git a/sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java new file mode 100644 index 00000000000..d10519ef9d9 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/computation/db/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.core.computation.db; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/computation/package-info.java b/sonar-core/src/main/java/org/sonar/core/computation/package-info.java new file mode 100644 index 00000000000..70ca84ceba5 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/computation/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.core.computation; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 639bbc835eb..694c2f2e182 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 701; + public static final int LAST_VERSION = 702; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL @@ -50,6 +50,7 @@ public class DatabaseVersion implements BatchComponent, ServerComponent { "active_rules", "active_rule_parameters", "activities", + "analysis_reports", "authors", "characteristics", "dashboards", diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 768edb20cb6..051892c4cc9 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -39,6 +39,8 @@ import org.sonar.core.component.ComponentDto; import org.sonar.core.component.SnapshotDto; import org.sonar.core.component.db.ComponentMapper; import org.sonar.core.component.db.SnapshotMapper; +import org.sonar.core.computation.db.AnalysisReportDto; +import org.sonar.core.computation.db.AnalysisReportMapper; import org.sonar.core.config.Logback; import org.sonar.core.dashboard.*; import org.sonar.core.dependency.DependencyDto; @@ -157,6 +159,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class); loadAlias(conf, "RequirementMigration", RequirementMigrationDto.class); loadAlias(conf, "Activity", ActivityDto.class); + loadAlias(conf, "AnalysisReport", AnalysisReportDto.class); // AuthorizationMapper has to be loaded before IssueMapper because this last one used it loadMapper(conf, "org.sonar.core.user.AuthorizationMapper"); @@ -174,7 +177,8 @@ public class MyBatis implements BatchComponent, ServerComponent { NotificationQueueMapper.class, CharacteristicMapper.class, GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class, - ProjectQgateAssociationMapper.class + ProjectQgateAssociationMapper.class, + AnalysisReportMapper.class }; loadMappers(conf, mappers); configureLogback(mappers); diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml new file mode 100644 index 00000000000..8183df183a8 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml @@ -0,0 +1,12 @@ + + + + + + + insert into activities + (project_key, report_status, report_data, created_at, updated_at) + values (#{projectKey}, #{status}, #{data}, #{createdAt}, #{updatedAt}) + + + diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 78c9e4ceb49..1c815129623 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -256,6 +256,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('583'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('584'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('700'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('701'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('702'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 013bbc2ad72..253cdc7a5f0 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -547,6 +547,15 @@ CREATE TABLE "ACTIVITIES" ( "DATA_FIELD" CLOB(2147483647) ); +CREATE TABLE "ANALYSIS_REPORTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "PROJECT_KEY" VARCHAR(400) NOT NULL, + "REPORT_STATUS" VARCHAR(20) NOT NULL, + "REPORT_DATA" CLOB(2147483647), + "CREATED_AT" TIMESTAMP NOT NULL, + "UPDATED_AT" TIMESTAMP +); + -- ---------------------------------------------- -- DDL Statements for indexes -- ---------------------------------------------- @@ -681,4 +690,6 @@ CREATE UNIQUE INDEX "ACTIVE_RULES_UNIQUE" ON "ACTIVE_RULES" ("PROFILE_ID","RULE_ CREATE INDEX "SNAPSHOT_DATA_RESOURCE_IDS" ON "SNAPSHOT_DATA" ("RESOURCE_ID"); -CREATE UNIQUE INDEX "QPROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE"); +CREATE UNIQUE INDEX "PROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE"); + +CREATE UNIQUE INDEX "ANALYSIS_REPORTS_PROJECT_KEY" ON "ANALYSIS_REPORTS" ("PROJECT_KEY"); -- 2.39.5