summaryrefslogtreecommitdiffstats
path: root/sonar-core/src/main
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-13 10:45:24 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-12-13 10:45:24 +0100
commitb8cf09bb9c0b0eb4a66d76f60dbe913be75717fa (patch)
tree00fb8963206eb3e0b84d6eedd75413d9c4cd140c /sonar-core/src/main
parentd2397318906b49c3b605185e75931029964b94ba (diff)
downloadsonarqube-b8cf09bb9c0b0eb4a66d76f60dbe913be75717fa.tar.gz
sonarqube-b8cf09bb9c0b0eb4a66d76f60dbe913be75717fa.zip
SONAR-4535 Create service action to create new Profile
Diffstat (limited to 'sonar-core/src/main')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/permission/GlobalPermissions.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java63
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java75
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleParamDto.java66
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveruleMapper.java29
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java34
-rw-r--r--sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java6
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml26
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml19
11 files changed, 328 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/permission/GlobalPermissions.java b/sonar-core/src/main/java/org/sonar/core/permission/GlobalPermissions.java
index 6e1e052bdc6..e76500ad6cd 100644
--- a/sonar-core/src/main/java/org/sonar/core/permission/GlobalPermissions.java
+++ b/sonar-core/src/main/java/org/sonar/core/permission/GlobalPermissions.java
@@ -42,4 +42,8 @@ public final class GlobalPermissions {
*/
public static final List<String> ALL = ImmutableList.of(SYSTEM_ADMIN, QUALITY_PROFILE_ADMIN, DASHBOARD_SHARING, SCAN_EXECUTION, DRY_RUN_EXECUTION, PROVISIONING);
+ private GlobalPermissions() {
+ // only static methods
+ }
+
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
index 36587a7a6d2..ada0107b857 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
@@ -31,6 +31,7 @@ import org.sonar.core.permission.PermissionDao;
import org.sonar.core.permission.PermissionTemplateDao;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.purge.PurgeDao;
+import org.sonar.core.qualityprofile.db.ActiveRuleDao;
import org.sonar.core.qualityprofile.db.QualityProfileDao;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceIndexerDao;
@@ -54,6 +55,7 @@ public final class DaoUtils {
ActionPlanDao.class,
ActionPlanStatsDao.class,
ActiveDashboardDao.class,
+ ActiveRuleDao.class,
AuthorDao.class,
AuthorizationDao.class,
DashboardDao.class,
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 1a112a7de87..2fb00f2a0bc 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
@@ -55,8 +55,7 @@ import org.sonar.core.properties.PropertiesMapper;
import org.sonar.core.properties.PropertyDto;
import org.sonar.core.purge.PurgeMapper;
import org.sonar.core.purge.PurgeableSnapshotDto;
-import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.core.qualityprofile.db.QualityProfileMapper;
+import org.sonar.core.qualityprofile.db.*;
import org.sonar.core.resource.*;
import org.sonar.core.rule.RuleDto;
import org.sonar.core.rule.RuleMapper;
@@ -139,6 +138,8 @@ public class MyBatis implements BatchComponent, ServerComponent {
loadAlias(conf, "UserWithPermission", UserWithPermissionDto.class);
loadAlias(conf, "GroupWithPermission", GroupWithPermissionDto.class);
loadAlias(conf, "QualityProfile", QualityProfileDto.class);
+ loadAlias(conf, "ActiveRule", ActiveRuleDto.class);
+ loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
@@ -154,7 +155,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, WidgetMapper.class, WidgetPropertyMapper.class,
MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class,
NotificationQueueMapper.class, CharacteristicMapper.class,
- GroupMembershipMapper.class, QualityProfileMapper.class
+ GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class
};
loadMappers(conf, mappers);
configureLogback(mappers);
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java
new file mode 100644
index 00000000000..2346103e655
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDao.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.qualityprofile.db;
+
+import org.apache.ibatis.session.SqlSession;
+import org.sonar.api.ServerComponent;
+import org.sonar.core.persistence.MyBatis;
+
+public class ActiveRuleDao implements ServerComponent {
+
+ private final MyBatis mybatis;
+
+ public ActiveRuleDao(MyBatis mybatis) {
+ this.mybatis = mybatis;
+ }
+
+ public void insert(ActiveRuleDto dto, SqlSession session) {
+ session.getMapper(ActiveRuleMapper.class).insert(dto);
+ }
+
+ public void insert(ActiveRuleDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ insert(dto, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void insert(ActiveRuleParamDto dto, SqlSession session) {
+ session.getMapper(ActiveRuleMapper.class).insertParameter(dto);
+ }
+
+ public void insert(ActiveRuleParamDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ insert(dto, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java
new file mode 100644
index 00000000000..1810c6854a5
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.qualityprofile.db;
+
+public class ActiveRuleDto {
+
+ private Integer id;
+ private Integer profileId;
+ private Integer ruleId;
+ private Integer severity;
+ private String inheritance;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public ActiveRuleDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public Integer getProfileId() {
+ return profileId;
+ }
+
+ public ActiveRuleDto setProfileId(Integer profileId) {
+ this.profileId = profileId;
+ return this;
+ }
+
+ public Integer getRulId() {
+ return ruleId;
+ }
+
+ public ActiveRuleDto setRuleId(Integer ruleId) {
+ this.ruleId = ruleId;
+ return this;
+ }
+
+ public Integer getSeverity() {
+ return severity;
+ }
+
+ public ActiveRuleDto setSeverity(Integer severity) {
+ this.severity = severity;
+ return this;
+ }
+
+ public String getInheritance() {
+ return inheritance;
+ }
+
+ public ActiveRuleDto setInheritance(String inheritance) {
+ this.inheritance = inheritance;
+ return this;
+ }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleParamDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleParamDto.java
new file mode 100644
index 00000000000..20dcad77895
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleParamDto.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.qualityprofile.db;
+
+public class ActiveRuleParamDto {
+
+ private Integer id;
+ private Integer activeRuleId;
+ private Integer rulesParameterId;
+ private String value;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public ActiveRuleParamDto setId(Integer id) {
+ this.id = id;
+ return this;
+ }
+
+ public Integer getActiveRuleId() {
+ return activeRuleId;
+ }
+
+ public ActiveRuleParamDto setActiveRuleId(Integer activeRuleId) {
+ this.activeRuleId = activeRuleId;
+ return this;
+ }
+
+ public Integer getRulesParameterId() {
+ return rulesParameterId;
+ }
+
+ public ActiveRuleParamDto setRulesParameterId(Integer rulesParameterId) {
+ this.rulesParameterId = rulesParameterId;
+ return this;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public ActiveRuleParamDto setValue(String value) {
+ this.value = value;
+ return this;
+ }
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveruleMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveruleMapper.java
new file mode 100644
index 00000000000..e4068570c50
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveruleMapper.java
@@ -0,0 +1,29 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.qualityprofile.db;
+
+public interface ActiveRuleMapper {
+
+ void insert(ActiveRuleDto dto);
+
+ void insertParameter(ActiveRuleParamDto dto);
+
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
index 8abf40b311d..fb158675c08 100644
--- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDao.java
@@ -43,4 +43,38 @@ public class QualityProfileDao implements ServerComponent {
}
}
+ public void insert(QualityProfileDto dto, SqlSession session) {
+ session.getMapper(QualityProfileMapper.class).insert(dto);
+ }
+
+ public void insert(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ insert(dto, session);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void update(QualityProfileDto dto) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).update(dto);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void delete(Integer id) {
+ SqlSession session = mybatis.openSession();
+ try {
+ session.getMapper(QualityProfileMapper.class).delete(id);
+ session.commit();
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
}
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
index 8e39c65a680..15acccf2e0e 100644
--- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
@@ -26,4 +26,10 @@ public interface QualityProfileMapper {
List<QualityProfileDto> selectAll();
+ void insert(QualityProfileDto dto);
+
+ void update(QualityProfileDto dto);
+
+ void delete(Integer id);
+
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml
new file mode 100644
index 00000000000..f7178820d9d
--- /dev/null
+++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/ActiveRuleMapper.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.qualityprofile.db.ActiveRuleMapper">
+
+ <sql id="activeRuleColumns">
+ p.id,
+ p.profile_id as profileId,
+ p.rule_id as ruleId,
+ p.failure_level as severity,
+ p.version as version,
+ p.used_profile as used
+ </sql>
+
+ <insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO active_rules (profile_id, rule_id, failure_level, inheritance)
+ VALUES (#{profileId}, #{ruleId}, #{severity}, #{inheritance})
+ </insert>
+
+ <insert id="insertParameter" parameterType="ActiveRuleParam" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO active_rule_parameters (active_rule_id, rules_parameter_id, value)
+ VALUES (#{activeRuleId}, #{rulesParameterId}, #{value})
+ </insert>
+
+</mapper>
+
diff --git a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
index 829b765e8e8..217ba29567b 100644
--- a/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/qualityprofile/db/QualityProfileMapper.xml
@@ -17,5 +17,24 @@
from rules_profiles p
</select>
+ <insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
+ INSERT INTO rules_profiles (name, language, parent_name, version, used_profile)
+ VALUES (#{name}, #{language}, #{parent}, #{version}, #{used})
+ </insert>
+
+ <update id="update" parameterType="QualityProfile">
+ UPDATE rules_profiles SET
+ name=#{name},
+ language=#{language},
+ parent_name=#{parent},
+ version=#{version},
+ used_profile=#{used}
+ WHERE id=#{id}
+ </update>
+
+ <update id="delete" parameterType="Integer">
+ DELETE FROM rules_profiles WHERE id=#{id}
+ </update>
+
</mapper>