aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-26 10:37:38 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2015-08-27 09:52:39 +0200
commitc34b9f3648628a836c437b29e2cf20f84ddd06b4 (patch)
treeefbf82416b4fa43f5d56e3c1e6a9b7c94ea9f6fd /sonar-db
parent534f06f13130dda4c572a4192ae6e8b0b9c48b30 (diff)
downloadsonarqube-c34b9f3648628a836c437b29e2cf20f84ddd06b4.tar.gz
sonarqube-c34b9f3648628a836c437b29e2cf20f84ddd06b4.zip
Remove PermissionTemplateDao#insert(String,String,String)
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java38
-rw-r--r--sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java4
-rw-r--r--sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java8
3 files changed, 12 insertions, 38 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
index 535d98648fd..fda57b228c8 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDao.java
@@ -30,7 +30,6 @@ import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.System2;
-import org.sonar.api.utils.internal.Uuids;
import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.MyBatis;
@@ -89,7 +88,7 @@ public class PermissionTemplateDao implements Dao {
* @return a non paginated list of groups.
*/
public List<GroupWithPermissionDto> selectGroups(DbSession session, PermissionQuery query, Long templateId) {
- Map<String, Object> params = groupsParamaters(query, templateId);
+ Map<String, Object> params = groupsParameters(query, templateId);
return mapper(session).selectGroups(params);
}
@@ -107,7 +106,7 @@ public class PermissionTemplateDao implements Dao {
}
private int countGroups(DbSession session, PermissionQuery query, long templateId, @Nullable String groupName) {
- Map<String, Object> parameters = groupsParamaters(query, templateId);
+ Map<String, Object> parameters = groupsParameters(query, templateId);
if (groupName != null) {
parameters.put("groupName", groupName.toUpperCase());
}
@@ -118,7 +117,7 @@ public class PermissionTemplateDao implements Dao {
return countGroups(session, query, templateId, groupName) > 0;
}
- private static Map<String, Object> groupsParamaters(PermissionQuery query, Long templateId) {
+ private static Map<String, Object> groupsParameters(PermissionQuery query, Long templateId) {
Map<String, Object> params = newHashMap();
params.put(QUERY_PARAMETER, query);
params.put(TEMPLATE_ID_PARAMETER, templateId);
@@ -180,29 +179,6 @@ public class PermissionTemplateDao implements Dao {
}
}
- /**
- * @deprecated since 5.2 use {@link #insert(DbSession, PermissionTemplateDto)}
- */
- @Deprecated
- public PermissionTemplateDto insert(String templateName, @Nullable String description, @Nullable String projectPattern) {
- Date creationDate = now();
-
- PermissionTemplateDto permissionTemplate = new PermissionTemplateDto()
- .setName(templateName)
- .setKee(generateTemplateKey(templateName))
- .setDescription(description)
- .setKeyPattern(projectPattern)
- .setCreatedAt(creationDate)
- .setUpdatedAt(creationDate);
-
- DbSession session = myBatis.openSession(false);
- try {
- return insert(session, permissionTemplate);
- } finally {
- MyBatis.closeQuietly(session);
- }
- }
-
public PermissionTemplateDto insert(DbSession session, PermissionTemplateDto permissionTemplate) {
mapper(session).insert(permissionTemplate);
session.commit();
@@ -367,14 +343,6 @@ public class PermissionTemplateDao implements Dao {
session.getMapper(PermissionTemplateMapper.class).deleteByGroupId(groupId);
}
- private String generateTemplateKey(String name) {
- if (PermissionTemplateDto.DEFAULT.getName().equals(name)) {
- return PermissionTemplateDto.DEFAULT.getKee();
- }
-
- return Uuids.create();
- }
-
private Date now() {
return new Date(system.now());
}
diff --git a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
index 68f7c1da41c..9e4b0e806fd 100644
--- a/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
+++ b/sonar-db/src/main/java/org/sonar/db/permission/PermissionTemplateDto.java
@@ -30,7 +30,9 @@ public class PermissionTemplateDto {
public static final PermissionTemplateDto DEFAULT = new PermissionTemplateDto()
.setName("Default template")
.setKee("default_template")
- .setDescription("This permission template will be used as default when no other permission configuration is available");
+ .setDescription("This permission template will be used as default when no other permission configuration is available")
+ .setCreatedAt(new Date())
+ .setUpdatedAt(new Date());
private Long id;
private String name;
diff --git a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
index 3c672eb5082..b403a838c27 100644
--- a/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/permission/PermissionTemplateDaoTest.java
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
@Category(DbTests.class)
public class PermissionTemplateDaoTest {
@@ -58,7 +59,10 @@ public class PermissionTemplateDaoTest {
Date now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
when(system.now()).thenReturn(now.getTime());
- PermissionTemplateDto permissionTemplate = underTest.insert("my template", "my description", "myregexp");
+ PermissionTemplateDto permissionTemplate = underTest.insert(dbTester.getSession(), newPermissionTemplateDto()
+ .setName("my template")
+ .setDescription("my description")
+ .setKeyPattern("myregexp"));
assertThat(permissionTemplate).isNotNull();
assertThat(permissionTemplate.getId()).isEqualTo(1L);
@@ -78,7 +82,7 @@ public class PermissionTemplateDaoTest {
when(myBatis.openSession(false)).thenReturn(session);
underTest = new PermissionTemplateDao(myBatis, system);
- PermissionTemplateDto permissionTemplate = underTest.insert(PermissionTemplateDto.DEFAULT.getName(), null, null);
+ PermissionTemplateDto permissionTemplate = underTest.insert(session, PermissionTemplateDto.DEFAULT);
verify(mapper).insert(permissionTemplate);
verify(session).commit();