aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 20:28:40 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-07-13 20:33:35 +0200
commit6cc4d52f9791ad2547111543e41662c7522f89b8 (patch)
treef10b9fb8965965f5c8ef504f6634c05a86f561bf /sonar-core
parent6df8db4603834eeb4d3b897487650ff6348da1d5 (diff)
downloadsonarqube-6cc4d52f9791ad2547111543e41662c7522f89b8.tar.gz
sonarqube-6cc4d52f9791ad2547111543e41662c7522f89b8.zip
SONAR-3633 improve the management of server-side settings
* do not save default resource permissions in a db migration but in a server-side extension * new component to save settings from server-side components. It will have to be used by ruby app later.
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java42
-rw-r--r--sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java3
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql22
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml12
-rw-r--r--sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java44
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties-result.xml12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties.xml12
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty-result.xml13
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty.xml13
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml18
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml13
11 files changed, 173 insertions, 31 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
index c21cd08f48e..a496d826fc6 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesDao.java
@@ -26,6 +26,7 @@ import org.sonar.api.ServerComponent;
import org.sonar.core.persistence.MyBatis;
import java.util.List;
+import java.util.Map;
public class PropertiesDao implements BatchComponent, ServerComponent {
@@ -89,4 +90,45 @@ public class PropertiesDao implements BatchComponent, ServerComponent {
MyBatis.closeQuietly(session);
}
}
+
+ public void deleteGlobalProperties() {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ mapper.deleteGlobalProperties();
+ session.commit();
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void deleteGlobalProperty(String key) {
+ SqlSession session = mybatis.openSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ mapper.deleteGlobalProperty(key);
+ session.commit();
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public void saveGlobalProperties(Map<String, String> properties) {
+ SqlSession session = mybatis.openBatchSession();
+ PropertiesMapper mapper = session.getMapper(PropertiesMapper.class);
+ try {
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ mapper.deleteGlobalProperty(entry.getKey());
+ }
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ mapper.insert(new PropertyDto().setKey(entry.getKey()).setValue(entry.getValue()));
+ }
+ session.commit();
+
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
}
diff --git a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
index 1f75ed36dfb..cb63e4bb227 100644
--- a/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/properties/PropertiesMapper.java
@@ -32,5 +32,6 @@ public interface PropertiesMapper {
PropertyDto selectByKey(PropertyDto key);
void update(PropertyDto property);
void insert(PropertyDto property);
-
+ void deleteGlobalProperty(String key);
+ void deleteGlobalProperties();
}
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 768c4f4dfe6..913e1ff6d9c 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
@@ -10,28 +10,6 @@ ALTER TABLE GROUP_ROLES ALTER COLUMN ID RESTART WITH 2;
INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1);
INSERT INTO GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2);
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (1, 'sonar.role.admin.TRK.defaultGroups', 'sonar-administrators');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (2, 'sonar.role.admin.TRK.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (3, 'sonar.role.user.TRK.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (4, 'sonar.role.user.TRK.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (5, 'sonar.role.codeviewer.TRK.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (6, 'sonar.role.codeviewer.TRK.defaultUsers', '');
-
--- COMPATIBILITY WITH OLD VERSIONS OF VIEWS PLUGIN -> see migration 320
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (7, 'sonar.role.admin.VW.defaultGroups', 'sonar-administrators');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (8, 'sonar.role.admin.VW.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (9, 'sonar.role.user.VW.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (10, 'sonar.role.user.VW.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (11, 'sonar.role.codeviewer.VW.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (12, 'sonar.role.codeviewer.VW.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (13, 'sonar.role.admin.SVW.defaultGroups', 'sonar-administrators');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (14, 'sonar.role.admin.SVW.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (15, 'sonar.role.user.SVW.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (16, 'sonar.role.user.SVW.defaultUsers', '');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (17, 'sonar.role.codeviewer.SVW.defaultGroups', 'Anyone,sonar-users');
-INSERT INTO PROPERTIES(ID, PROP_KEY, TEXT_VALUE) VALUES (18, 'sonar.role.codeviewer.SVW.defaultUsers', '');
-ALTER TABLE PROPERTIES ALTER COLUMN ID RESTART WITH 19;
-
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('2');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('10');
diff --git a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
index 768ee357f24..d3d55c0008f 100644
--- a/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/properties/PropertiesMapper.xml
@@ -50,13 +50,13 @@
update properties set text_value = #{value} where id = #{id}
</update>
- <insert id="insert" parameterType="Property" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insert" parameterType="Property" useGeneratedKeys="false">
INSERT INTO properties (prop_key, resource_id, user_id, text_value)
VALUES (#{key}, #{resourceId}, #{userId}, #{value})
</insert>
<!-- Oracle -->
- <insert id="insert" databaseId="oracle" parameterType="Property" useGeneratedKeys="true" keyProperty="id">
+ <insert id="insert" databaseId="oracle" parameterType="Property" useGeneratedKeys="false">
<selectKey order="BEFORE" resultType="Long" keyProperty="id">
select properties_seq.NEXTVAL from DUAL
</selectKey>
@@ -64,4 +64,12 @@
VALUES (#{id}, #{key}, #{resourceId}, #{userId}, #{value})
</insert>
+ <delete id="deleteGlobalProperty" parameterType="string">
+ delete from properties where prop_key=#{id} and resource_id is null and user_id is null
+ </delete>
+
+ <delete id="deleteGlobalProperties">
+ delete from properties where resource_id is null and user_id is null
+ </delete>
+
</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
index 20c39047808..6fef82d9fd7 100644
--- a/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/properties/PropertiesDaoTest.java
@@ -19,11 +19,13 @@
*/
package org.sonar.core.properties;
+import com.google.common.collect.Maps;
import org.junit.Before;
import org.junit.Test;
import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.List;
+import java.util.TreeMap;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
@@ -34,12 +36,12 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
private PropertiesDao dao;
@Before
- public void createDao() throws Exception {
+ public void createDao() {
dao = new PropertiesDao(getMyBatis());
}
@Test
- public void shouldFindUserIdsForFavouriteResource() throws Exception {
+ public void shouldFindUserIdsForFavouriteResource() {
setupData("shouldFindUserIdsForFavouriteResource");
List<String> userIds = dao.findUserIdsForFavouriteResource(2L);
assertThat(userIds.size(), is(2));
@@ -47,7 +49,7 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
}
@Test
- public void selectGlobalProperties() throws Exception {
+ public void selectGlobalProperties() {
setupData("selectGlobalProperties");
List<PropertyDto> properties = dao.selectGlobalProperties();
assertThat(properties.size(), is(2));
@@ -62,7 +64,7 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
}
@Test
- public void selectProjectProperties() throws Exception {
+ public void selectProjectProperties() {
setupData("selectProjectProperties");
List<PropertyDto> properties = dao.selectProjectProperties("org.struts:struts");
assertThat(properties.size(), is(1));
@@ -73,7 +75,7 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
}
@Test
- public void setProperty_update() throws Exception {
+ public void setProperty_update() {
setupData("update");
dao.setProperty(new PropertyDto().setKey("global.key").setValue("new_global"));
@@ -85,7 +87,7 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
}
@Test
- public void setProperty_insert() throws Exception {
+ public void setProperty_insert() {
setupData("insert");
dao.setProperty(new PropertyDto().setKey("global.key").setValue("new_global"));
@@ -95,6 +97,36 @@ public class PropertiesDaoTest extends AbstractDaoTestCase {
checkTables("insert", "properties");
}
+ @Test
+ public void deleteGlobalProperties() {
+ setupData("deleteGlobalProperties");
+
+ dao.deleteGlobalProperties();
+
+ checkTables("deleteGlobalProperties", "properties");
+ }
+
+ @Test
+ public void deleteGlobalProperty() {
+ setupData("deleteGlobalProperty");
+
+ dao.deleteGlobalProperty("to_be_deleted");
+
+ checkTables("deleteGlobalProperty", "properties");
+ }
+
+ @Test
+ public void saveGlobalProperties() {
+ setupData("saveGlobalProperties");
+
+ TreeMap<String, String> props = Maps.newTreeMap();
+ props.put("to_be_inserted", "inserted");
+ props.put("to_be_updated", "updated");
+ dao.saveGlobalProperties(props);
+
+ checkTable("saveGlobalProperties", "properties", "prop_key", "text_value", "resource_id", "user_id");
+ }
+
private PropertyDto findById(List<PropertyDto> properties, int id) {
for (PropertyDto property : properties) {
if (property.getId() == id) {
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties-result.xml
new file mode 100644
index 00000000000..a5cfed3378b
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties-result.xml
@@ -0,0 +1,12 @@
+<dataset>
+
+ <!-- global -->
+ <!--<properties id="1" prop_key="global.key" text_value="new_global" resource_id="[null]" user_id="[null]"/>-->
+
+ <!-- project -->
+ <properties id="2" prop_key="project.key" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="3" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties.xml
new file mode 100644
index 00000000000..3e5eb87705c
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperties.xml
@@ -0,0 +1,12 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.key" text_value="new_global" resource_id="[null]" user_id="[null]"/>
+
+ <!-- project -->
+ <properties id="2" prop_key="project.key" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="3" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty-result.xml
new file mode 100644
index 00000000000..0428139feb6
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty-result.xml
@@ -0,0 +1,13 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.key" text_value="new_global" resource_id="[null]" user_id="[null]"/>
+ <!--<properties id="2" prop_key="to_be_deleted" text_value="xxx" resource_id="[null]" user_id="[null]"/>-->
+
+ <!-- project -->
+ <properties id="3" prop_key="to_be_deleted" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty.xml
new file mode 100644
index 00000000000..aaf0fd642d3
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/deleteGlobalProperty.xml
@@ -0,0 +1,13 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="global.key" text_value="new_global" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="to_be_deleted" text_value="xxx" resource_id="[null]" user_id="[null]"/>
+
+ <!-- project - do not delete this project property that has the same key -->
+ <properties id="3" prop_key="to_be_deleted" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml
new file mode 100644
index 00000000000..f12984a944b
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties-result.xml
@@ -0,0 +1,18 @@
+<dataset>
+
+ <!-- global -->
+ <!--<properties id="1" prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>-->
+ <properties id="2" prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
+
+ <!-- project - do not update this project property that has the same key -->
+ <properties id="3" prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+
+ <properties id="5" prop_key="to_be_inserted" text_value="inserted" resource_id="[null]" user_id="[null]"/>
+ <properties id="6" prop_key="to_be_updated" text_value="updated" resource_id="[null]" user_id="[null]"/>
+
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml
new file mode 100644
index 00000000000..b0fa0be6deb
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/properties/PropertiesDaoTest/saveGlobalProperties.xml
@@ -0,0 +1,13 @@
+<dataset>
+
+ <!-- global -->
+ <properties id="1" prop_key="to_be_updated" text_value="old value" resource_id="[null]" user_id="[null]"/>
+ <properties id="2" prop_key="to_not_change" text_value="xxx" resource_id="[null]" user_id="[null]"/>
+
+ <!-- project - do not update this project property that has the same key -->
+ <properties id="3" prop_key="to_be_updated" text_value="new_project" resource_id="10" user_id="[null]"/>
+
+ <!-- user -->
+ <properties id="4" prop_key="user.key" text_value="new_user" resource_id="[null]" user_id="100"/>
+
+</dataset>