diff options
65 files changed, 689 insertions, 513 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java index ea34d448ac6..734a9ff75b0 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java @@ -143,7 +143,8 @@ public class PersistComponentsStep implements ComputationStep { } else if (type == Component.Type.VIEW) { qualifier = VIEW; } - dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, projectUuid, isRootPrivate, qualifier, componentName, false); + dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, projectUuid, isRootPrivate, + "", qualifier, componentName, false); } private static boolean isRootPrivate(Component root, Map<String, ComponentDto> existingDtosByUuids) { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java index ae139fc0b77..0fab00a6fd7 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/ProjectConfigurationFactoryTest.java @@ -52,7 +52,7 @@ public class ProjectConfigurationFactoryTest { @Test public void return_project_settings() { ComponentDto project = db.components().insertPrivateProject(); - db.properties().insertProperties(null, project.name(), project.qualifier(), + db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("1").setValue("val1"), newComponentPropertyDto(project).setKey("2").setValue("val2"), newComponentPropertyDto(project).setKey("3").setValue("val3")); @@ -68,7 +68,7 @@ public class ProjectConfigurationFactoryTest { public void project_settings_override_global_settings() { settings.setProperty("key", "value"); ComponentDto project = db.components().insertPrivateProject(); - db.properties().insertProperties(null, project.name(), project.qualifier(), + db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("key").setValue("value2")); Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl()); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java index 488507409e3..661fa932bc4 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ConfigurationRepositoryTest.java @@ -139,7 +139,7 @@ public class ConfigurationRepositoryTest { } private void insertProjectProperty(ComponentDto project, String propertyKey, String propertyValue) { - db.properties().insertProperties(null, project.name(), project.qualifier(), + db.properties().insertProperties(null, project.getKey(), project.name(), project.qualifier(), new PropertyDto().setKey(propertyKey).setValue(propertyValue).setComponentUuid(project.uuid())); } } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java b/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java index f7eca8e91b9..ea1c3b3475c 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/db/ReadOnlyPropertiesDao.java @@ -44,7 +44,7 @@ public class ReadOnlyPropertiesDao extends PropertiesDao { @Override public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, - @Nullable String projectName, @Nullable String qualifier) { + @Nullable String projectKey, @Nullable String projectName, @Nullable String qualifier) { // do nothing } @@ -54,12 +54,13 @@ public class ReadOnlyPropertiesDao extends PropertiesDao { } @Override - public void deleteProjectProperty(String key, String projectUuid, String projectName, String qualifier) { + public void deleteProjectProperty(String key, String projectUuid, String projectKey, String projectName, String qualifier) { // do nothing } @Override - public void deleteProjectProperty(DbSession session, String key, String projectUuid, String projectName, String qualifier) { + public void deleteProjectProperty(DbSession session, String key, String projectUuid, String projectKey, + String projectName, String qualifier) { // do nothing } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 50fe9c75f8f..d566a60c46a 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -144,7 +144,7 @@ public class ComputeEngineContainerImplTest { private void insertProperty(String key, String value) { PropertyDto dto = new PropertyDto().setKey(key).setValue(value); - db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto, null, null, null); + db.getDbClient().propertiesDao().saveProperty(db.getSession(), dto, null, null, null, null); db.commit(); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/db/ReadOnlyPropertiesDaoTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/db/ReadOnlyPropertiesDaoTest.java index 83894a129bc..0aa81667d56 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/db/ReadOnlyPropertiesDaoTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/db/ReadOnlyPropertiesDaoTest.java @@ -40,7 +40,7 @@ public class ReadOnlyPropertiesDaoTest { @Test public void insertProperty() { - underTest.saveProperty(dbSession, propertyDto, null, null, null); + underTest.saveProperty(dbSession, propertyDto, null, null, null, null); assertNoInteraction(); } @@ -54,7 +54,7 @@ public class ReadOnlyPropertiesDaoTest { @Test public void deleteProjectProperty() { - underTest.deleteProjectProperty(null, null, null, null); + underTest.deleteProjectProperty(null, null, null, null, null, null); assertNoInteraction(); @@ -62,7 +62,7 @@ public class ReadOnlyPropertiesDaoTest { @Test public void deleteProjectProperty1() { - underTest.deleteProjectProperty(dbSession, null, null, null, null); + underTest.deleteProjectProperty(dbSession, null, null, null, null, null); assertNoInteraction(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java index 9668dcbda25..4f4965e56b9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/ProjectAlmSettingDao.java @@ -48,7 +48,8 @@ public class ProjectAlmSettingDao implements Dao { this.auditPersister = auditPersister; } - public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key, String projectName) { + public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key, + String projectName, String projectKey) { String uuid = uuidFactory.create(); long now = system2.now(); ProjectAlmSettingMapper mapper = getMapper(dbSession); @@ -63,7 +64,8 @@ public class ProjectAlmSettingDao implements Dao { projectAlmSettingDto.setUpdatedAt(now); if (auditPersister != null) { - DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName); + DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, + projectName, projectKey); if (isUpdate) { auditPersister.updateDevOpsPlatformSetting(dbSession, value); } else { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java index 51925c8c673..b3c359b04be 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/ComponentNewValue.java @@ -31,45 +31,40 @@ public class ComponentNewValue extends NewValue { private String description; private String rootComponentUuid; private String path; - private String key; + private String componentKey; private Boolean isPrivate; private Boolean isEnabled; private String qualifier; - public ComponentNewValue(String componentUuid, String name, String key, @Nullable String qualifier) { + public ComponentNewValue(String componentUuid, String name, String componentKey, @Nullable String qualifier) { this.componentUuid = componentUuid; this.componentName = name; - this.key = key; + this.componentKey = componentKey; this.qualifier = getQualifier(qualifier); } - public ComponentNewValue(String rootComponentUuid, boolean isPrivate, @Nullable String qualifier) { - this.rootComponentUuid = rootComponentUuid; - this.isPrivate = isPrivate; - this.qualifier = getQualifier(qualifier); - } - - public ComponentNewValue(String componentUuid, String name, boolean isPrivate, String qualifier) { + public ComponentNewValue(String componentUuid, String name, String componentKey, boolean isPrivate, String qualifier) { this.componentUuid = componentUuid; this.componentName = name; + this.componentKey = componentKey; this.isPrivate = isPrivate; this.qualifier = getQualifier(qualifier); } - public ComponentNewValue(String uuid, String name, String key, boolean enabled, String path, @Nullable String qualifier) { + public ComponentNewValue(String uuid, String name, String componentKey, boolean enabled, String path, @Nullable String qualifier) { this.componentUuid = uuid; this.componentName = name; this.isEnabled = enabled; this.path = path; - this.key = key; + this.componentKey = componentKey; this.qualifier = getQualifier(qualifier); } - public ComponentNewValue(String uuid, boolean isPrivate, String name, String key, @Nullable String description, @Nullable String qualifier) { + public ComponentNewValue(String uuid, boolean isPrivate, String name, String componentKey, @Nullable String description, @Nullable String qualifier) { this.componentUuid = uuid; this.isPrivate = isPrivate; this.componentName = name; - this.key = key; + this.componentKey = componentKey; this.description = description; this.qualifier = getQualifier(qualifier); } @@ -87,8 +82,8 @@ public class ComponentNewValue extends NewValue { return description; } - public String getKey() { - return key; + public String getComponentKey() { + return componentKey; } public boolean isPrivate() { @@ -104,10 +99,10 @@ public class ComponentNewValue extends NewValue { StringBuilder sb = new StringBuilder("{"); addField(sb, "\"componentUuid\": ", this.componentUuid, true); addField(sb, "\"rootComponentUuid\": ", this.rootComponentUuid, true); + addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"qualifier\": ", this.qualifier, true); addField(sb, "\"description\": ", this.description, true); - addField(sb, "\"key\": ", this.key, true); addField(sb, "\"path\": ", this.path, true); addField(sb, "\"isPrivate\": ", ObjectUtils.toString(this.isPrivate), false); addField(sb, "\"isEnabled\": ", ObjectUtils.toString(this.isEnabled), false); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java index a9b4dfa1dbc..5a9237b0913 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/DevOpsPlatformSettingNewValue.java @@ -49,6 +49,9 @@ public class DevOpsPlatformSettingNewValue extends NewValue { private String projectUuid; @Nullable + private String projectKey; + + @Nullable private String projectName; @Nullable @@ -77,10 +80,11 @@ public class DevOpsPlatformSettingNewValue extends NewValue { this.clientId = dto.getClientId(); } - public DevOpsPlatformSettingNewValue(ProjectAlmSettingDto dto, String key, String projectName) { + public DevOpsPlatformSettingNewValue(ProjectAlmSettingDto dto, String key, String projectName, String projectKey) { this.devOpsPlatformSettingUuid = dto.getAlmSettingUuid(); this.key = key; this.projectUuid = dto.getProjectUuid(); + this.projectKey = projectKey; this.projectName = projectName; this.almRepo = dto.getAlmRepo(); this.almSlug = dto.getAlmSlug(); @@ -90,6 +94,7 @@ public class DevOpsPlatformSettingNewValue extends NewValue { public DevOpsPlatformSettingNewValue(ProjectDto projectDto) { this.projectUuid = projectDto.getUuid(); + this.projectKey = projectDto.getKey(); this.projectName = projectDto.getName(); } @@ -129,6 +134,11 @@ public class DevOpsPlatformSettingNewValue extends NewValue { } @CheckForNull + public String getProjectKey() { + return this.projectKey; + } + + @CheckForNull public String getProjectName() { return this.projectName; } @@ -163,6 +173,7 @@ public class DevOpsPlatformSettingNewValue extends NewValue { addField(sb, "\"appId\": ", this.appId, true); addField(sb, "\"clientId\": ", this.clientId, true); addField(sb, "\"projectUuid\": ", this.projectUuid, true); + addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"projectName\": ", this.projectName, true); addField(sb, "\"almRepo\": ", this.almRepo, true); addField(sb, "\"almSlug\": ", this.almSlug, true); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java index 4b6569f947d..e18885ebc9b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java @@ -31,20 +31,22 @@ public class GroupPermissionNewValue extends PermissionNewValue { @Nullable private String groupName; - public GroupPermissionNewValue(String uuid, String rootComponentUuid, String componentName, String role, String groupUuid, - String groupName, String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { - super(uuid, rootComponentUuid, componentName, role, qualifier, permissionTemplateDto); + public GroupPermissionNewValue(String uuid, String rootComponentUuid, String componentKey, String componentName, + String role, String groupUuid, String groupName, String qualifier, + @Nullable PermissionTemplateDto permissionTemplateDto) { + super(uuid, rootComponentUuid, componentKey, componentName, role, qualifier, permissionTemplateDto); this.groupUuid = groupUuid; this.groupName = groupName; } - public GroupPermissionNewValue(String rootComponentUuid, String componentName, String role, String groupUuid, - String groupName, String qualifier) { - this(null, rootComponentUuid, componentName, role, groupUuid, groupName, qualifier, null); + public GroupPermissionNewValue(String rootComponentUuid, String componentKey, String componentName, String role, + String groupUuid, String groupName, String qualifier) { + this(null, rootComponentUuid, componentKey, componentName, role, groupUuid, groupName, qualifier, null); } - public GroupPermissionNewValue(GroupPermissionDto dto, String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { - this(dto.getUuid(), dto.getComponentUuid(), dto.getComponentName(), dto.getRole(), dto.getGroupUuid(), + public GroupPermissionNewValue(GroupPermissionDto dto, @Nullable String componentKey, @Nullable String qualifier, + @Nullable PermissionTemplateDto permissionTemplateDto) { + this(dto.getUuid(), dto.getComponentUuid(), componentKey, dto.getComponentName(), dto.getRole(), dto.getGroupUuid(), dto.getGroupName(), qualifier, permissionTemplateDto); } @@ -66,6 +68,7 @@ public class GroupPermissionNewValue extends PermissionNewValue { addField(sb, "\"groupUuid\": ", this.groupUuid, true); addField(sb, "\"groupName\": ", this.groupName, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); + addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java index fd3de2db3a5..ad2e0badcb7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PermissionNewValue.java @@ -31,6 +31,9 @@ public abstract class PermissionNewValue extends NewValue { protected String componentUuid; @Nullable + protected String componentKey; + + @Nullable protected String componentName; @Nullable @@ -45,10 +48,11 @@ public abstract class PermissionNewValue extends NewValue { @Nullable protected String permissionTemplateName; - protected PermissionNewValue(@Nullable String permissionUuid, @Nullable String componentUuid, @Nullable String componentName, - @Nullable String permission, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { + protected PermissionNewValue(@Nullable String permissionUuid, @Nullable String componentUuid, @Nullable String componentKey, + @Nullable String componentName, @Nullable String permission, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplateDto) { this.permissionUuid = permissionUuid; this.componentUuid = componentUuid; + this.componentKey = componentKey; this.componentName = componentName; this.qualifier = getQualifier(qualifier); this.permission = permission; @@ -77,6 +81,11 @@ public abstract class PermissionNewValue extends NewValue { } @CheckForNull + public String getComponentKey() { + return this.componentKey; + } + + @CheckForNull public String getQualifier() { return this.qualifier; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java index 3169c6ba55c..2de53c1714a 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/PropertyNewValue.java @@ -41,6 +41,9 @@ public class PropertyNewValue extends NewValue { private String componentUuid; @Nullable + private String componentKey; + + @Nullable private String componentName; @Nullable @@ -54,11 +57,13 @@ public class PropertyNewValue extends NewValue { setValue(propertyKey, userPropertyDto.getValue()); } - public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentName, @Nullable String qualifier) { + public PropertyNewValue(PropertyDto propertyDto, @Nullable String userLogin, @Nullable String componentKey, + @Nullable String componentName, @Nullable String qualifier) { this.propertyKey = propertyDto.getKey(); this.userUuid = propertyDto.getUserUuid(); this.userLogin = userLogin; this.componentUuid = propertyDto.getComponentUuid(); + this.componentKey = componentKey; this.componentName = componentName; this.qualifier = getQualifier(qualifier); @@ -81,10 +86,11 @@ public class PropertyNewValue extends NewValue { setValue(propertyKey, propertyValue); } - public PropertyNewValue(@Nullable String propertyKey, @Nullable String projectUuid, + public PropertyNewValue(@Nullable String propertyKey, @Nullable String projectUuid, @Nullable String componentKey, @Nullable String componentName, @Nullable String qualifier, @Nullable String userUuid) { this.propertyKey = propertyKey; this.componentUuid = projectUuid; + this.componentKey = componentKey; this.componentName = componentName; this.userUuid = userUuid; this.qualifier = getQualifier(qualifier); @@ -116,6 +122,11 @@ public class PropertyNewValue extends NewValue { } @CheckForNull + public String getComponentKey() { + return this.componentKey; + } + + @CheckForNull public String getComponentName() { return this.componentName; } @@ -133,6 +144,7 @@ public class PropertyNewValue extends NewValue { addField(sb, "\"userUuid\": ", this.userUuid, true); addField(sb, "\"userLogin\": ", this.userLogin, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); + addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"qualifier\": ", this.qualifier, true); endString(sb); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java index 6e96398c983..cd441d1cfeb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java @@ -32,20 +32,21 @@ public class UserPermissionNewValue extends PermissionNewValue { @Nullable private final String userLogin; - public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String projectName, @Nullable UserId userId, - String qualifier, @Nullable PermissionTemplateDto templateDto) { - super(permissionDto.getUuid(), permissionDto.getComponentUuid(), projectName, permissionDto.getPermission(), + public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String componentKey, @Nullable String componentName, + @Nullable UserId userId, String qualifier, @Nullable PermissionTemplateDto templateDto) { + super(permissionDto.getUuid(), permissionDto.getComponentUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } - public UserPermissionNewValue(UserId userId, String qualifier) { - this(null, null, null, userId, qualifier); + public UserPermissionNewValue(UserId userId, @Nullable String qualifier) { + this(null, null, null, null, userId, qualifier); } - public UserPermissionNewValue(String role, String projectUuid, String projectName, UserId userId, String qualifier) { - super(null, projectUuid, projectName, role, qualifier, null); + public UserPermissionNewValue(String role, String componentUuid, String componentKey, String componentName, UserId userId, + String qualifier) { + super(null, componentUuid, componentKey, componentName, role, qualifier, null); this.userUuid = userId != null ? userId.getUuid() : null; this.userLogin = userId != null ? userId.getLogin() : null; } @@ -66,6 +67,7 @@ public class UserPermissionNewValue extends PermissionNewValue { addField(sb, "\"permissionUuid\": ", this.permissionUuid, true); addField(sb, "\"permission\": ", this.permission, true); addField(sb, "\"componentUuid\": ", this.componentUuid, true); + addField(sb, "\"componentKey\": ", this.componentKey, true); addField(sb, "\"componentName\": ", this.componentName, true); addField(sb, "\"permissionTemplateUuid\": ", this.permissionTemplateId, true); addField(sb, "\"permissionTemplateName\": ", this.permissionTemplateName, true); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java index 30cab0b497f..9e63312898c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/WebhookNewValue.java @@ -38,28 +38,33 @@ public class WebhookNewValue extends NewValue { private String projectUuid; @Nullable + private String projectKey; + + @Nullable private String projectName; - public WebhookNewValue(WebhookDto dto, @Nullable String projectName) { - this(dto.getUuid(), dto.getName(), dto.getProjectUuid(), projectName, dto.getUrl()); + public WebhookNewValue(WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) { + this(dto.getUuid(), dto.getName(), dto.getProjectUuid(), projectKey, projectName, dto.getUrl()); } public WebhookNewValue(String webhookUuid, String webhookName) { - this.webhookUuid = webhookUuid; this.name = webhookName; } - public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectName, @Nullable String url) { + public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectKey, + @Nullable String projectName, @Nullable String url) { this.webhookUuid = webhookUuid; this.name = webhookName; this.url = url; this.projectUuid = projectUuid; + this.projectKey = projectKey; this.projectName = projectName; } public WebhookNewValue(ProjectDto projectDto) { this.projectUuid = projectDto.getUuid(); + this.projectKey = projectDto.getKey(); this.projectName = projectDto.getName(); } @@ -84,6 +89,11 @@ public class WebhookNewValue extends NewValue { } @CheckForNull + public String getProjectKey() { + return this.projectKey; + } + + @CheckForNull public String getProjectName() { return this.projectName; } @@ -95,6 +105,7 @@ public class WebhookNewValue extends NewValue { addField(sb, "\"name\": ", this.name, true); addField(sb, "\"url\": ", this.url, true); addField(sb, "\"projectUuid\": ", this.projectUuid, true); + addField(sb, "\"projectKey\": ", this.projectKey, true); addField(sb, "\"projectName\": ", this.projectName, true); endString(sb); return sb.toString(); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java index 110bd365e05..40888a9a045 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java @@ -377,9 +377,9 @@ public class ComponentDao implements Dao { } public void setPrivateForRootComponentUuid(DbSession session, String projectUuid, boolean isPrivate, - @Nullable String qualifier, String componentName, boolean track) { + String key, @Nullable String qualifier, String componentName, boolean track) { if (track && auditPersister != null) { - ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, isPrivate, qualifier); + ComponentNewValue componentNewValue = new ComponentNewValue(projectUuid, componentName, key, isPrivate, qualifier); auditPersister.updateComponentVisibility(session, componentNewValue, qualifier); } mapper(session).setPrivateForRootComponentUuid(projectUuid, isPrivate); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index a864531b9ff..31c8e799749 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -129,8 +129,9 @@ public class GroupPermissionDao implements Dao { mapper(dbSession).insert(groupPermissionDto); if (auditPersister != null) { + String componentKey = (componentDto != null) ? componentDto.getKey() : null; String qualifier = (componentDto != null) ? componentDto.qualifier() : null; - auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, qualifier, permissionTemplateDto)); + auditPersister.addGroupPermission(dbSession, new GroupPermissionNewValue(groupPermissionDto, componentKey, qualifier, permissionTemplateDto)); } } @@ -142,7 +143,7 @@ public class GroupPermissionDao implements Dao { if (deletedRecords > 0 && auditPersister != null) { auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(), - component.name(), null, null, null, component.qualifier())); + component.getKey(), component.name(), null, null, null, component.qualifier())); } } @@ -155,7 +156,7 @@ public class GroupPermissionDao implements Dao { if (deletedRecords > 0 && auditPersister != null) { auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(), - component.name(), null, groupUuid, "", component.qualifier())); + component.getKey(), component.name(), null, groupUuid, "", component.qualifier())); } return deletedRecords; } @@ -165,7 +166,7 @@ public class GroupPermissionDao implements Dao { if (deletedRecords > 0 && auditPersister != null) { auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(), - component.name(), null, null, null, component.qualifier())); + component.getKey(), component.name(), null, null, null, component.qualifier())); } return deletedRecords; @@ -179,7 +180,7 @@ public class GroupPermissionDao implements Dao { if (deletedRecords > 0 && auditPersister != null) { auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(component.uuid(), - component.name(), permission, null, null, component.qualifier())); + component.getKey(), component.name(), permission, null, null, component.qualifier())); } return deletedRecords; @@ -206,9 +207,10 @@ public class GroupPermissionDao implements Dao { if (deletedRecords > 0 && auditPersister != null) { String qualifier = (componentDto != null) ? componentDto.qualifier() : null; + String componentKey = (componentDto != null) ? componentDto.getKey() : null; String componentName = (componentDto != null) ? componentDto.name() : null; auditPersister.deleteGroupPermission(dbSession, new GroupPermissionNewValue(rootComponentUuid, - componentName, permission, groupUuid, groupName, qualifier)); + componentKey, componentName, permission, groupUuid, groupName, qualifier)); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java index f321b9d1ba9..f269ee5acad 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDao.java @@ -122,8 +122,9 @@ public class UserPermissionDao implements Dao { if (auditPersister != null) { String componentName = (componentDto != null) ? componentDto.name() : null; + String componentKey = (componentDto != null) ? componentDto.getKey() : null; String qualifier = (componentDto != null) ? componentDto.qualifier() : null; - auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentName, userId, qualifier, + auditPersister.addUserPermission(dbSession, new UserPermissionNewValue(dto, componentKey, componentName, userId, qualifier, templateDto)); } } @@ -135,7 +136,7 @@ public class UserPermissionDao implements Dao { int deletedRows = mapper(dbSession).deleteGlobalPermission(user.getUuid(), permission); if (deletedRows > 0 && auditPersister != null) { - auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, null, null, user, null)); + auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, null, null, null, user, null)); } } @@ -146,7 +147,8 @@ public class UserPermissionDao implements Dao { int deletedRows = mapper(dbSession).deleteProjectPermission(user.getUuid(), permission, component.uuid()); if (deletedRows > 0 && auditPersister != null) { - auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, component.uuid(), component.name(), user, component.qualifier())); + auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, component.uuid(), component.getKey(), + component.name(), user, component.qualifier())); } } @@ -157,7 +159,8 @@ public class UserPermissionDao implements Dao { int deletedRows = mapper(dbSession).deleteProjectPermissions(component.uuid()); if (deletedRows > 0 && auditPersister != null) { - auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(null, component.uuid(), component.name(), null, component.qualifier())); + auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(null, component.uuid(), component.getKey(), + component.name(), null, component.qualifier())); } } @@ -168,7 +171,8 @@ public class UserPermissionDao implements Dao { int deletedRows = mapper(dbSession).deleteProjectPermissionOfAnyUser(project.uuid(), permission); if (deletedRows > 0 && auditPersister != null) { - auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, project.uuid(), project.name(), null, project.qualifier())); + auditPersister.deleteUserPermission(dbSession, new UserPermissionNewValue(permission, project.uuid(), project.getKey(), + project.name(), null, project.qualifier())); } return deletedRows; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index d971fac1b70..138c402fd47 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -109,9 +109,9 @@ public class PropertiesDao implements Dao { } try (DbSession session = mybatis.openSession(false); - Connection connection = session.getConnection(); - PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection); - ResultSet rs = pstmt.executeQuery()) { + Connection connection = session.getConnection(); + PreparedStatement pstmt = createStatement(projectUuid, dispatcherKeys, connection); + ResultSet rs = pstmt.executeQuery()) { return rs.next() && rs.getInt(1) > 0; } catch (SQLException e) { throw new IllegalStateException("Fail to execute SQL for hasProjectNotificationSubscribersForDispatchers", e); @@ -210,15 +210,15 @@ public class PropertiesDao implements Dao { * * @throws IllegalArgumentException if {@link PropertyDto#getKey()} is {@code null} or empty */ - public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectName, - @Nullable String qualifier) { + public void saveProperty(DbSession session, PropertyDto property, @Nullable String userLogin, @Nullable String projectKey, + @Nullable String projectName, @Nullable String qualifier) { int affectedRows = save(getMapper(session), property.getKey(), property.getUserUuid(), property.getComponentUuid(), property.getValue()); if (auditPersister != null && auditPersister.isTrackedProperty(property.getKey())) { if (affectedRows > 0) { - auditPersister.updateProperty(session, new PropertyNewValue(property, userLogin, projectName, qualifier), false); + auditPersister.updateProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false); } else { - auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectName, qualifier), false); + auditPersister.addProperty(session, new PropertyNewValue(property, userLogin, projectKey, projectName, qualifier), false); } } } @@ -253,7 +253,7 @@ public class PropertiesDao implements Dao { public void saveProperty(PropertyDto property) { try (DbSession session = mybatis.openSession(false)) { - saveProperty(session, property, null, null, null); + saveProperty(session, property, null, null, null, null); session.commit(); } } @@ -270,33 +270,36 @@ public class PropertiesDao implements Dao { if (deletedRows > 0 && auditPersister != null && query.key() != null && auditPersister.isTrackedProperty(query.key())) { auditPersister.deleteProperty(dbSession, new PropertyNewValue(query.key(), query.componentUuid(), - null, null, query.userUuid()), false); + null, null, null, query.userUuid()), false); } return deletedRows; } - public int delete(DbSession dbSession, PropertyDto dto, @Nullable String userLogin, @Nullable String projectName, @Nullable String qualifier) { + public int delete(DbSession dbSession, PropertyDto dto, @Nullable String userLogin, @Nullable String projectKey, + @Nullable String projectName, @Nullable String qualifier) { int deletedRows = getMapper(dbSession).delete(dto.getKey(), dto.getUserUuid(), dto.getComponentUuid()); if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(dto.getKey())) { - auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectName, qualifier), false); + auditPersister.deleteProperty(dbSession, new PropertyNewValue(dto, userLogin, projectKey, projectName, qualifier), + false); } return deletedRows; } - public void deleteProjectProperty(String key, String projectUuid, String projectName, String qualifier) { + public void deleteProjectProperty(String key, String projectUuid, String projectKey, String projectName, String qualifier) { try (DbSession session = mybatis.openSession(false)) { - deleteProjectProperty(session, key, projectUuid, projectName, qualifier); + deleteProjectProperty(session, key, projectUuid, projectKey, projectName, qualifier); session.commit(); } } - public void deleteProjectProperty(DbSession session, String key, String projectUuid, String projectName, String qualifier) { + public void deleteProjectProperty(DbSession session, String key, String projectUuid, String projectKey, + String projectName, String qualifier) { int deletedRows = getMapper(session).deleteProjectProperty(key, projectUuid); if (deletedRows > 0 && auditPersister != null && auditPersister.isTrackedProperty(key)) { - auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectName, qualifier, + auditPersister.deleteProperty(session, new PropertyNewValue(key, projectUuid, projectKey, projectName, qualifier, null), false); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java index 088e35f478a..43e962d7f97 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/webhook/WebhookDao.java @@ -56,19 +56,19 @@ public class WebhookDao implements Dao { return mapper(dbSession).selectForProjectUuidOrderedByName(projectDto.getUuid()); } - public void insert(DbSession dbSession, WebhookDto dto, @Nullable String projectName) { + public void insert(DbSession dbSession, WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) { mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now())); if (auditPersister != null) { - auditPersister.addWebhook(dbSession, new WebhookNewValue(dto, projectName)); + auditPersister.addWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName)); } } - public void update(DbSession dbSession, WebhookDto dto, @Nullable String projectName) { + public void update(DbSession dbSession, WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) { mapper(dbSession).update(dto.setUpdatedAt(system2.now())); if (auditPersister != null) { - auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectName)); + auditPersister.updateWebhook(dbSession, new WebhookNewValue(dto, projectKey, projectName)); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java index 1cab7cbd08c..6824adb0734 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java @@ -57,7 +57,8 @@ public class ProjectAlmSettingDaoTest { ProjectDto project = db.components().insertPrivateProjectDto(); ProjectDto anotherProject = db.components().insertPrivateProjectDto(); ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSettingDto, project); - underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, githubAlmSettingDto.getKey(), anotherProject.getName()); + underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, githubAlmSettingDto.getKey(), anotherProject.getName(), + anotherProject.getKey()); assertThat(underTest.selectByProject(dbSession, project).get()) .extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, @@ -78,11 +79,11 @@ public class ProjectAlmSettingDaoTest { ProjectDto project = db.components().insertPrivateProjectDto(); ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project); bitbucketProjectAlmSettingDto.setAlmSlug("slug1"); - underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto, almSettingsDto.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto, almSettingsDto.getKey(), project.getName(), project.getKey()); ProjectAlmSettingDto bitbucketProjectAlmSettingDto2 = newBitbucketProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto()); bitbucketProjectAlmSettingDto2.setAlmSlug("slug2"); when(uuidFactory.create()).thenReturn(A_UUID + 1); - underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, bitbucketProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName(), project.getKey()); Set<String> slugs = new HashSet<>(); slugs.add("slug1"); @@ -106,11 +107,11 @@ public class ProjectAlmSettingDaoTest { ProjectDto project = db.components().insertPrivateProjectDto(); ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(almSettingsDto, project); githubProjectAlmSettingDto.setAlmRepo("repo1"); - underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, almSettingsDto.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto, almSettingsDto.getKey(), project.getName(), project.getKey()); ProjectAlmSettingDto githubProjectAlmSettingDto2 = newGithubProjectAlmSettingDto(almSettingsDto, db.components().insertPrivateProjectDto()); githubProjectAlmSettingDto2.setAlmRepo("repo2"); when(uuidFactory.create()).thenReturn(A_UUID + 1); - underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto2, almSettingsDto.getKey(), project.getName(), project.getKey()); Set<String> repos = new HashSet<>(); repos.add("repo1"); @@ -138,7 +139,7 @@ public class ProjectAlmSettingDaoTest { system2.setNow(A_DATE_LATER); ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project) .setSummaryCommentEnabled(false); - underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, githubAlmSetting.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, githubAlmSetting.getKey(), project.getName(), project.getKey()); assertThat(underTest.selectByProject(dbSession, project).get()) .extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java index cb1bc266a1a..018bda5d50e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoWithPersisterTest.java @@ -63,21 +63,22 @@ public class ProjectAlmSettingDaoWithPersisterTest { ProjectDto project = db.components().insertPrivateProjectDto(); ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project) .setSummaryCommentEnabled(false); - underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName(), project.getKey()); verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture()); DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue(); assertThat(newValue) .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey, - DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName) - .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey(), project.getUuid(), project.getName()); + DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectKey, + DevOpsPlatformSettingNewValue::getProjectName) + .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey(), project.getUuid(), project.getKey(), project.getName()); assertThat(newValue.toString()).doesNotContain("\"url\""); AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting(); system2.setNow(A_DATE_LATER); ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project) .setSummaryCommentEnabled(false); - underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, anotherGithubAlmSetting.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto, anotherGithubAlmSetting.getKey(), project.getName(), project.getKey()); verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); @@ -99,14 +100,15 @@ public class ProjectAlmSettingDaoWithPersisterTest { ProjectDto project = db.components().insertPrivateProjectDto(); ProjectAlmSettingDto projectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSetting, project) .setSummaryCommentEnabled(false); - underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName()); + underTest.insertOrUpdate(dbSession, projectAlmSettingDto, githubAlmSetting.getKey(), project.getName(), project.getKey()); underTest.deleteByProject(dbSession, project); verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture()); DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue(); assertThat(newValue) - .extracting(DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectName) - .containsExactly(project.getUuid(), project.getName()); + .extracting(DevOpsPlatformSettingNewValue::getProjectUuid, DevOpsPlatformSettingNewValue::getProjectKey, + DevOpsPlatformSettingNewValue::getProjectName) + .containsExactly(project.getUuid(), project.getKey(), project.getName()); assertThat(newValue.toString()).doesNotContain("devOpsPlatformSettingUuid"); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java index f959cc148a2..1bebbaab39e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java @@ -48,10 +48,11 @@ public class ComponentNewValueTest { @Test public void toString_project_uuid_and_name_and_isPrivate() { - ComponentNewValue newValue = new ComponentNewValue("uuid", "name", true,"TRK"); + ComponentNewValue newValue = new ComponentNewValue("uuid", "name", "key", true,"TRK"); assertThat(newValue.toString()) .contains("\"componentUuid\": \"uuid\"") + .contains("\"componentKey\": \"key\"") .contains("\"componentName\": \"name\"") .contains("\"qualifier\": \"project\"") .contains("\"isPrivate\": true"); @@ -65,7 +66,7 @@ public class ComponentNewValueTest { .contains("\"componentUuid\": \"uuid\"") .contains("\"componentName\": \"name\"") .contains("\"qualifier\": \"project\"") - .contains("\"key\": \"key\""); + .contains("\"componentKey\": \"key\""); } @Test @@ -77,7 +78,7 @@ public class ComponentNewValueTest { .contains("\"componentName\": \"name\"") .contains("\"qualifier\": \"project\"") .contains("\"isPrivate\": true") - .contains("\"key\": \"key\"") + .contains("\"componentKey\": \"key\"") .contains("\"description\": \"description\""); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 411cdb3ec52..dde9a0beda0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -1772,7 +1772,7 @@ public class ComponentDaoTest { db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(), }; - underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true, null, "name", true); + underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true, "key", null, "name", true); assertThat(privateFlagOfUuid(uuids[0])).isTrue(); assertThat(privateFlagOfUuid(uuids[1])).isTrue(); @@ -1780,7 +1780,7 @@ public class ComponentDaoTest { assertThat(privateFlagOfUuid(uuids[3])).isFalse(); assertThat(privateFlagOfUuid(uuids[4])).isFalse(); - underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false, null, "name", true); + underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, false, "key", null, "name", true); assertThat(privateFlagOfUuid(uuids[0])).isFalse(); assertThat(privateFlagOfUuid(uuids[1])).isFalse(); @@ -1788,7 +1788,7 @@ public class ComponentDaoTest { assertThat(privateFlagOfUuid(uuids[3])).isFalse(); assertThat(privateFlagOfUuid(uuids[4])).isFalse(); - underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false, null, "name", true); + underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, false, "key", null, "name", true); assertThat(privateFlagOfUuid(uuids[0])).isFalse(); assertThat(privateFlagOfUuid(uuids[1])).isFalse(); @@ -1796,7 +1796,7 @@ public class ComponentDaoTest { assertThat(privateFlagOfUuid(uuids[3])).isFalse(); assertThat(privateFlagOfUuid(uuids[4])).isFalse(); - underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true, null, "name", true); + underTest.setPrivateForRootComponentUuid(db.getSession(), uuid2, true, "key", null, "name", true); assertThat(privateFlagOfUuid(uuids[0])).isFalse(); assertThat(privateFlagOfUuid(uuids[1])).isFalse(); @@ -1884,7 +1884,7 @@ public class ComponentDaoTest { @Test public void setPrivateForRootComponentUuid_auditPersisterIsCalled() { - underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP, "appName", true); + underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, "key", APP, "appName", true); verify(auditPersister, Mockito.times(1)) .updateComponentVisibility(any(DbSession.class), any(ComponentNewValue.class), anyString()); @@ -1892,7 +1892,7 @@ public class ComponentDaoTest { @Test public void setPrivateForRootComponentUuid_withoutTrack_auditPersisterIsNotCalled() { - underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, APP, "appName", false); + underTestWithAuditPersister.setPrivateForRootComponentUuid(dbSession, "anyUuid", false, "key", APP, "appName", false); verifyNoInteractions(auditPersister); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java index b2ae70f6c66..f633f63febd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterTest.java @@ -62,14 +62,14 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), null, dto.getRole(), null, null); + assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), null, dto.getRole(), null, null, null); assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\" }"); underTest.delete(dbSession, ADMIN, group.getUuid(), group.getName(), null, null); verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, group.getUuid(), group.getName(), null, ADMIN, null, null); + assertNewValue(newValue, null, group.getUuid(), group.getName(), null, ADMIN, null, null, null); assertThat(newValue).hasToString("{\"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\" }"); } @@ -86,16 +86,17 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.name(), "project"); + assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.getKey(), + project.name(), "project"); assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\"," + - " \"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); + " \"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); underTest.deleteByRootComponentUuid(dbSession, project); verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, null, null, project.uuid(), null, project.name(), "project"); - assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); + assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "project"); + assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); } @Test @@ -114,16 +115,17 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.name(), "project"); + assertNewValue(newValue, dto.getUuid(), null, null, project.uuid(), dto.getRole(), project.getKey(), project.name(), "project"); assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"componentUuid\": \"cuuid\", " - + "\"componentName\": \"cname\", \"qualifier\": \"project\" }"); + + "\"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); underTest.deleteByRootComponentUuidForAnyOne(dbSession, project); verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, null, null, project.uuid(), null, project.name(), "project"); - assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); + assertNewValue(newValue, null, null, null, project.uuid(), null, project.getKey(), project.name(), "project"); + assertThat(newValue).hasToString("{\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", " + + "\"componentName\": \"cname\", \"qualifier\": \"project\" }"); } @Test @@ -142,16 +144,17 @@ public class GroupPermissionDaoWithPersisterTest { verify(auditPersister).addGroupPermission(eq(dbSession), newValueCaptor.capture()); GroupPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.name(), "project"); + assertNewValue(newValue, dto.getUuid(), group.getUuid(), group.getName(), project.uuid(), dto.getRole(), project.getKey(), project.name(), "project"); assertThat(newValue).hasToString("{\"permissionUuid\": \"1\", \"permission\": \"admin\", \"groupUuid\": \"guuid\", \"groupName\": \"gname\", " - + "\"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); + + "\"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); underTest.deleteByRootComponentUuidAndPermission(dbSession, dto.getRole(), project); verify(auditPersister).deleteGroupPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, null, null, project.uuid(), ADMIN, project.name(), "project"); - assertThat(newValue).hasToString("{\"permission\": \"admin\", \"componentUuid\": \"cuuid\", \"componentName\": \"cname\", \"qualifier\": \"project\" }"); + assertNewValue(newValue, null, null, null, project.uuid(), ADMIN, project.getKey(), project.name(), "project"); + assertThat(newValue).hasToString("{\"permission\": \"admin\", \"componentUuid\": \"cuuid\", \"componentKey\": \"cKey\"," + + " \"componentName\": \"cname\", \"qualifier\": \"project\" }"); } @Test @@ -166,21 +169,24 @@ public class GroupPermissionDaoWithPersisterTest { verifyNoMoreInteractions(auditPersister); } - private void assertNewValue(GroupPermissionNewValue newValue, String uuid, String groupUuid, String groupName, String cUuid, String permission, String cName, String qualifier) { + private void assertNewValue(GroupPermissionNewValue newValue, String uuid, String groupUuid, String groupName, String cUuid, String permission, + String componentKey, String cName, String qualifier) { assertThat(newValue) - .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission", "componentName", "qualifier") - .containsExactly(uuid, groupUuid, groupName, cUuid, permission, cName, qualifier); + .extracting("permissionUuid", "groupUuid", "groupName", "componentUuid", "permission", + "componentKey", "componentName", "qualifier") + .containsExactly(uuid, groupUuid, groupName, cUuid, permission, componentKey, + cName, qualifier); } private void addGroupPermission() { group = db.users().insertGroup(g -> g.setUuid("guuid").setName("gname")); - project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname")); + project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setDbKey("cKey")); dto = getGroupPermission(group, project); underTest.insert(dbSession, dto, project, null); } private void addGroupPermissionWithoutGroup() { - project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname")); + project = db.components().insertPrivateProject(c -> c.setUuid("cuuid").setName("cname").setDbKey("cKey")); dto = getGroupPermission(project); underTest.insert(dbSession, dto, project, null); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java index f32a4905119..b1c8f862f50 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDaoWithPersisterTest.java @@ -61,14 +61,14 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null); + assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null, null); assertThat(newValue.toString()).doesNotContain("projectUuid"); underTest.deleteGlobalPermission(dbSession, user, SYSTEM_ADMIN); verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null); + assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, dto.getPermission(), null, null, null); assertThat(newValue.toString()).doesNotContain("permissionUuid"); } @@ -111,14 +111,16 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project"); + assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), + project.getKey(), project.name(), "project"); assertThat(newValue.toString()).contains("componentUuid"); underTest.deleteProjectPermission(dbSession, user, SYSTEM_ADMIN, project); verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), project.name(), "project"); + assertNewValue(newValue, null, user.getUuid(), user.getLogin(), project.uuid(), dto.getPermission(), + project.getKey(), project.name(), "project"); assertThat(newValue.toString()).doesNotContain("permissionUuid"); } @@ -143,7 +145,8 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), portfolio.uuid(), dto.getPermission(), portfolio.name(), "portfolio"); + assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), portfolio.uuid(), dto.getPermission(), + portfolio.getKey(), portfolio.name(), "portfolio"); assertThat(newValue.toString()).contains("componentUuid"); } @@ -156,7 +159,8 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).addUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), application.uuid(), dto.getPermission(), application.name(), "application"); + assertNewValue(newValue, dto.getUuid(), user.getUuid(), user.getLogin(), application.uuid(), dto.getPermission(), + application.getKey(), application.name(), "application"); assertThat(newValue.toString()).contains("componentUuid"); } @@ -170,7 +174,8 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(), project.name(), "project"); + assertNewValue(newValue, null, null, null, project.uuid(), dto.getPermission(), + project.getKey(), project.name(), "project"); assertThat(newValue.toString()).doesNotContain("userUuid"); } @@ -194,7 +199,8 @@ public class UserPermissionDaoWithPersisterTest { verify(auditPersister).deleteUserPermission(eq(dbSession), newValueCaptor.capture()); UserPermissionNewValue newValue = newValueCaptor.getValue(); - assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, null, null, null); + assertNewValue(newValue, null, user.getUuid(), user.getLogin(), null, null, null, + null, null); assertThat(newValue.toString()).contains("userUuid"); } @@ -208,12 +214,13 @@ public class UserPermissionDaoWithPersisterTest { verifyNoMoreInteractions(auditPersister); } - private void assertNewValue(UserPermissionNewValue newValue, String permissionUuid, String userUuid, String userLogin, String componentUuid, String permission, - String componentName, String qualifier) { + private void assertNewValue(UserPermissionNewValue newValue, String permissionUuid, String userUuid, String userLogin, String componentUuid, + String permission, String componentKey, String componentName, String qualifier) { assertThat(newValue) .extracting(UserPermissionNewValue::getPermissionUuid, UserPermissionNewValue::getUserUuid, UserPermissionNewValue::getUserLogin, - UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier) - .containsExactly(permissionUuid, userUuid, userLogin, componentUuid, permission, componentName, qualifier); + UserPermissionNewValue::getComponentUuid, UserPermissionNewValue::getPermission, + UserPermissionNewValue::getComponentKey, UserPermissionNewValue::getComponentName, UserPermissionNewValue::getQualifier) + .containsExactly(permissionUuid, userUuid, userLogin, componentUuid, permission, componentKey, componentName, qualifier); } private UserDto insertUser(Consumer<UserDto> populateUserDto) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index b4ceac8d737..58637968dcc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -97,11 +97,16 @@ public class PropertiesDaoTest { UserDto user1 = db.users().insertUser(u -> u.setLogin("user1")); UserDto user2 = db.users().insertUser(u -> u.setLogin("user2")); UserDto user3 = db.users().insertUser(u -> u.setLogin("user3")); - insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name()); - insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid(), user3.getLogin(), null); - insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid(), user1.getLogin(), project2.name()); - insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), project1.name()); - insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid(), user3.getLogin(), project2.name()); + insertProperty("notification.NewViolations.Email", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), + project1.getKey(), project1.name()); + insertProperty("notification.NewViolations.Twitter", "true", null, user3.getUuid(), user3.getLogin(), + null, null); + insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user1.getUuid(), user1.getLogin(), + project2.getKey(), project2.name()); + insertProperty("notification.NewViolations.Twitter", "true", project1.uuid(), user2.getUuid(), user2.getLogin(), + project1.getKey(), project1.name()); + insertProperty("notification.NewViolations.Twitter", "true", project2.uuid(), user3.getUuid(), user3.getLogin(), + project2.getKey(), project2.name()); db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1); db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project2); db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project2); @@ -136,22 +141,23 @@ public class PropertiesDaoTest { UserDto user1 = db.users().insertUser(u -> u.setLogin("user1")); UserDto user2 = db.users().insertUser(u -> u.setLogin("user2")); String projectUuid = randomAlphabetic(8); + String projectKey = randomAlphabetic(4); String projectName = randomAlphabetic(4); db.components().insertPrivateProject(projectUuid); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, - user2.getUuid(), user2.getLogin(), null); + user2.getUuid(), user2.getLogin(), null, null); // project subscription insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectUuid, user1.getUuid(), - user1.getLogin(), projectName); + user1.getLogin(), projectKey, projectName); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", "uuid56", user1.getUuid(), - user1.getLogin(), projectName); + user1.getLogin(), projectKey, projectName); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectUuid, user1.getUuid(), - user1.getLogin(), projectName); + user1.getLogin(), projectKey, projectName); // global subscription insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, user2.getUuid(), - user2.getLogin(), null); + user2.getLogin(), null,null); // Nobody is subscribed assertThat(underTest.hasProjectNotificationSubscribersForDispatchers(projectUuid, singletonList("NotSexyDispatcher"))) @@ -211,14 +217,19 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), + project.getKey(), project.name()); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), + project.getKey(), project.name()); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null)) .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2"))); @@ -243,14 +254,19 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), + project.getKey(), project.name()); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), + project.getKey(), project.name()); Set<String> allLogins = of("user1", "user2", "user3", "user4"); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins)) @@ -286,14 +302,19 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), + project.getKey(), project.name()); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), + project.getKey(), project.name()); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( @@ -325,14 +346,19 @@ public class PropertiesDaoTest { String channelKey = randomAlphabetic(7); String otherChannelKey = randomAlphabetic(8); // user1 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); // user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 subscribed on project only - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user3.getUuid(), user3.getLogin(), + project.getKey(), project.name()); // user4 did not subscribe - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", project.uuid(), user4.getUuid(), user4.getLogin(), + project.getKey(), project.name()); Set<String> allLogins = of("user1", "user2", "user3", "user4"); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) @@ -372,13 +398,19 @@ public class PropertiesDaoTest { String dispatcherKey = randomAlphabetic(4); String channelKey = randomAlphabetic(5); // user1 and user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name()); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), + project.getKey(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 and user4 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), + null, null); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( @@ -402,13 +434,19 @@ public class PropertiesDaoTest { String dispatcherKey = randomAlphabetic(4); String channelKey = randomAlphabetic(5); // user1 and user2 subscribed on project and globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), project.name()); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user1.getUuid(), user1.getLogin(), + null, null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user1.getUuid(), user1.getLogin(), + project.getKey(), project.name()); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user2.getUuid(), user2.getLogin(), + project.getKey(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", project.uuid(), user2.getUuid(), user2.getLogin(), + project.getKey(), project.name()); // user3 and user4 subscribed only globally - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), null); - insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user3.getUuid(), user3.getLogin(), + project.getKey(), null); + insertProperty(propertyKeyOf(dispatcherKey, channelKey), "true", null, user4.getUuid(), user4.getLogin(), + null, null); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) .containsOnly( @@ -423,8 +461,8 @@ public class PropertiesDaoTest { @Test public void selectGlobalProperties() { // global - insertProperty("global.one", "one", null, null, null, null); - insertProperty("global.two", "two", null, null, null, null); + insertProperty("global.one", "one", null, null, null, null,null); + insertProperty("global.two", "two", null, null, null, null,null); List<PropertyDto> properties = underTest.selectGlobalProperties(); assertThat(properties.size()) @@ -442,7 +480,7 @@ public class PropertiesDaoTest { @Test @UseDataProvider("allValuesForSelect") public void selectGlobalProperties_supports_all_values(String dbValue, String expected) { - insertProperty("global.one", dbValue, null, null, null, null); + insertProperty("global.one", dbValue, null, null, null, null, null); List<PropertyDto> dtos = underTest.selectGlobalProperties(); assertThat(dtos) @@ -456,12 +494,12 @@ public class PropertiesDaoTest { @Test public void selectGlobalProperty() { // global - insertProperty("global.one", "one", null, null, null, null); - insertProperty("global.two", "two", null, null, null, null); + insertProperty("global.one", "one", null, null, null, null,null); + insertProperty("global.two", "two", null, null, null, null, null); // project - insertProperty("project.one", "one", "uuid10", null, null, "component"); + insertProperty("project.one", "one", "uuid10", null, null, "component", "component"); // user - insertProperty("user.one", "one", null, "100", "login", null); + insertProperty("user.one", "one", null, "100", "login", null, null); assertThat(underTest.selectGlobalProperty("global.one")) .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) @@ -475,7 +513,7 @@ public class PropertiesDaoTest { @Test @UseDataProvider("allValuesForSelect") public void selectGlobalProperty_supports_all_values(String dbValue, String expected) { - insertProperty("global.one", dbValue, null, null, null, null); + insertProperty("global.one", dbValue, null, null, null, null, null); assertThat(underTest.selectGlobalProperty("global.one")) .extracting(PropertyDto::getComponentUuid, PropertyDto::getUserUuid, PropertyDto::getValue) @@ -487,11 +525,11 @@ public class PropertiesDaoTest { ComponentDto projectDto = insertPrivateProject("A"); String projectUuid = projectDto.uuid(); // global - insertProperty("global.one", "one", null, null, null, null); - insertProperty("global.two", "two", null, null, null, null); + insertProperty("global.one", "one", null, null, null, null, null); + insertProperty("global.two", "two", null, null, null, null, null); // project - insertProperty("project.one", "Pone", projectUuid, null, null, projectDto.name()); - insertProperty("project.two", "Ptwo", projectUuid, null, null, projectDto.name()); + insertProperty("project.one", "Pone", projectUuid, null, null, projectDto.getKey(), projectDto.name()); + insertProperty("project.two", "Ptwo", projectUuid, null, null, projectDto.getKey(), projectDto.name()); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos) @@ -509,7 +547,7 @@ public class PropertiesDaoTest { @UseDataProvider("allValuesForSelect") public void selectProjectProperties_supports_all_values(String dbValue, String expected) { ComponentDto projectDto = insertPrivateProject("A"); - insertProperty("project.one", dbValue, projectDto.uuid(), null, null, projectDto.name()); + insertProperty("project.one", dbValue, projectDto.uuid(), null, null, projectDto.getKey(), projectDto.name()); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos).hasSize(1); @@ -532,7 +570,7 @@ public class PropertiesDaoTest { @Test public void selectProjectProperty() { - insertProperty("project.one", "one", "uuid10", null, null, "component"); + insertProperty("project.one", "one", "uuid10", null, null, "component", "component"); PropertyDto property = underTest.selectProjectProperty("uuid10", "project.one"); @@ -544,17 +582,17 @@ public class PropertiesDaoTest { @Test public void select_by_query() { // global - insertProperty("global.one", "one", null, null, null, null); - insertProperty("global.two", "two", null, null, null, null); + insertProperty("global.one", "one", null, null, null, null, null); + insertProperty("global.two", "two", null, null, null, null, null); // struts - insertProperty("struts.one", "one", "uuid10", null, null, "component"); + insertProperty("struts.one", "one", "uuid10", null, null, "component", "component"); // commons - insertProperty("commonslang.one", "one", "uuid11", null, null, "component"); + insertProperty("commonslang.one", "one", "uuid11", null, null, "component", "component"); // user - insertProperty("user.one", "one", null, "100", "login", null); - insertProperty("user.two", "two", "uuid10", "100", "login", "component"); + insertProperty("user.one", "one", null, "100", "login", null, null); + insertProperty("user.two", "two", "uuid10", "100", "login", "component", "component"); // other - insertProperty("other.one", "one", "uuid12", null, null, "component"); + insertProperty("other.one", "one", "uuid12", null, null, "component", "component"); List<PropertyDto> results = underTest.selectByQuery(PropertyQuery.builder().setKey("user.two").setComponentUuid("uuid10") .setUserUuid("100").build(), db.getSession()); @@ -573,14 +611,14 @@ public class PropertiesDaoTest { String key = "key"; String anotherKey = "anotherKey"; - insertProperty(key, "value", null, null, null, null); - insertProperty(key, "value", "uuid10", null, null, "component"); - insertProperty(key, "value", null, user.getUuid(), user.getLogin(), null); - insertProperty(anotherKey, "value", null, null, null, null); + insertProperty(key, "value", null, null, null, null, null); + insertProperty(key, "value", "uuid10", null, null, "component", "component"); + insertProperty(key, "value", null, user.getUuid(), user.getLogin(), null, null); + insertProperty(anotherKey, "value", null, null, null, null, null); - insertProperty("key1", "value", null, null, null, null); - insertProperty("key2", "value", null, null, null, null); - insertProperty("key3", "value", null, null, null, null); + insertProperty("key1", "value", null, null, null, null, null); + insertProperty("key2", "value", null, null, null, null, null); + insertProperty("key3", "value", null, null, null, null, null); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key))) .extracting("key") @@ -608,11 +646,11 @@ public class PropertiesDaoTest { String key = "key"; String anotherKey = "anotherKey"; - insertProperties(null, null, newGlobalPropertyDto().setKey(key)); - insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key)); - insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key), + insertProperties(null, null, null, newGlobalPropertyDto().setKey(key)); + insertProperties(null, project.getKey(), project.name(), newComponentPropertyDto(project).setKey(key)); + insertProperties(null, project2.getKey(), project2.name(), newComponentPropertyDto(project2).setKey(key), newComponentPropertyDto(project2).setKey(anotherKey)); - insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key)); + insertProperties(user.getLogin(), null, null, newUserPropertyDto(user).setKey(key)); newUserPropertyDto(user).setKey(key); @@ -635,11 +673,11 @@ public class PropertiesDaoTest { String key = "key"; String anotherKey = "anotherKey"; - insertProperties(null, null, newGlobalPropertyDto().setKey(key)); - insertProperties(null, project.name(), newComponentPropertyDto(project).setKey(key)); - insertProperties(null, project2.name(), newComponentPropertyDto(project2).setKey(key), + insertProperties(null, null,null, newGlobalPropertyDto().setKey(key)); + insertProperties(null, project.getKey(), project.name(), newComponentPropertyDto(project).setKey(key)); + insertProperties(null, project2.getKey(), project2.name(), newComponentPropertyDto(project2).setKey(key), newComponentPropertyDto(project2).setKey(anotherKey)); - insertProperties(user.getLogin(), null, newUserPropertyDto(user).setKey(key)); + insertProperties(user.getLogin(), null, null, newUserPropertyDto(user).setKey(key)); assertThat(underTest.selectPropertiesByKeysAndComponentUuids(session, newHashSet(key), newHashSet(project.uuid()))) .extracting("key", "componentUuid").containsOnly(tuple(key, project.uuid())); @@ -662,10 +700,10 @@ public class PropertiesDaoTest { public void select_by_key_and_matching_value() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); - db.properties().insertProperties(null, project1.name(), project1.qualifier(), newComponentPropertyDto("key", "value", project1)); - db.properties().insertProperties(null, project2.name(), project2.qualifier(), newComponentPropertyDto("key", "value", project2)); - db.properties().insertProperties(null, null, null, newGlobalPropertyDto("key", "value")); - db.properties().insertProperties(null, project1.name(), project1.qualifier(), newComponentPropertyDto("another key", "value", project1)); + db.properties().insertProperties(null, project1.getKey(), project1.name(), project1.qualifier(), newComponentPropertyDto("key", "value", project1)); + db.properties().insertProperties(null, project2.getKey(), project2.name(), project2.qualifier(), newComponentPropertyDto("key", "value", project2)); + db.properties().insertProperties(null, null, null, null, newGlobalPropertyDto("key", "value")); + db.properties().insertProperties(null, project1.getKey(), project1.name(), project1.qualifier(), newComponentPropertyDto("another key", "value", project1)); assertThat(underTest.selectByKeyAndMatchingValue(db.getSession(), "key", "value")) .extracting(PropertyDto::getValue, PropertyDto::getComponentUuid) @@ -682,12 +720,17 @@ public class PropertiesDaoTest { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto file1 = db.components().insertComponent(ComponentTesting.newFileDto(project1)); ComponentDto project2 = db.components().insertPrivateProject(); - db.properties().insertProperties(user1.getLogin(), project1.name(), project1.qualifier(), newPropertyDto("key", "1", project1, user1)); - db.properties().insertProperties(user1.getLogin(), project2.name(), project2.qualifier(), newPropertyDto("key", "2", project2, user1)); - db.properties().insertProperties(user1.getLogin(), file1.name(), null, newPropertyDto("key", "3", file1, user1)); - db.properties().insertProperties(user1.getLogin(), project1.name(), project1.qualifier(), newPropertyDto("another key", "4", project1, user1)); - db.properties().insertProperties(user2.getLogin(), project1.name(), project1.qualifier(), newPropertyDto("key", "5", project1, user2)); - db.properties().insertProperties(null, null, null, newGlobalPropertyDto("key", "global")); + db.properties().insertProperties(user1.getLogin(), project1.getKey(), project1.name(), project1.qualifier(), + newPropertyDto("key", "1", project1, user1)); + db.properties().insertProperties(user1.getLogin(), project1.getKey(), project2.name(), project2.qualifier(), + newPropertyDto("key", "2", project2, user1)); + db.properties().insertProperties(user1.getLogin(), null, file1.name(), null, + newPropertyDto("key", "3", file1, user1)); + db.properties().insertProperties(user1.getLogin(), project1.getKey(), project1.name(), project1.qualifier(), + newPropertyDto("another key", "4", project1, user1)); + db.properties().insertProperties(user2.getLogin(), project1.getKey(), project1.name(), project1.qualifier(), + newPropertyDto("key", "5", project1, user2)); + db.properties().insertProperties(null, null, null, null, newGlobalPropertyDto("key", "global")); assertThat(underTest.selectByKeyAndUserUuidAndComponentQualifier(db.getSession(), "key", user1.getUuid(), "TRK")) .extracting(PropertyDto::getValue).containsExactlyInAnyOrder("1", "2"); @@ -806,7 +849,7 @@ public class PropertiesDaoTest { @Test @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_global_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) { - String uuid = insertProperty("global", oldValue, null, null, null, null); + String uuid = insertProperty("global", oldValue, null, null, null, null, null); underTest.saveProperty(new PropertyDto().setKey("global").setValue(newValue)); @@ -830,7 +873,7 @@ public class PropertiesDaoTest { @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_component_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) { String componentUuid = "uuid999"; - String uuid = insertProperty("global", oldValue, componentUuid, null, null, "component"); + String uuid = insertProperty("global", oldValue, componentUuid, null, null, "component", "component"); underTest.saveProperty(new PropertyDto().setKey("global").setComponentUuid(componentUuid).setValue(newValue)); @@ -853,7 +896,7 @@ public class PropertiesDaoTest { @UseDataProvider("valueUpdatesDataProvider") public void saveProperty_deletes_then_inserts_user_properties_when_they_exist_in_db(@Nullable String oldValue, @Nullable String newValue) { String userUuid = "uuid-90"; - String uuid = insertProperty("global", oldValue, null, userUuid, "login", null); + String uuid = insertProperty("global", oldValue, null, userUuid, "login", null, null); underTest.saveProperty(new PropertyDto().setKey("global").setUserUuid(userUuid).setValue(newValue)); @@ -912,15 +955,15 @@ public class PropertiesDaoTest { insertPrivateProject("A"); insertPrivateProject("B"); insertPrivateProject("C"); - String uuid1 = insertProperty("global.one", "one", null, null, null, null); - String uuid2 = insertProperty("global.two", "two", null, null, null, null); - String uuid3 = insertProperty("struts.one", "one", "project1", null, null, "project1"); - String uuid4 = insertProperty("commonslang.one", "one", "project2", null, null, "project2"); - String uuid5 = insertProperty("user.one", "one", null, "100", "login", null); - String uuid6 = insertProperty("user.two", "two", null, "100", "login", null); - String uuid7 = insertProperty("other.one", "one", "project3", null, null, "project3"); + String uuid1 = insertProperty("global.one", "one", null, null, null, null, null); + String uuid2 = insertProperty("global.two", "two", null, null, null, null, null); + String uuid3 = insertProperty("struts.one", "one", "project1", null, null, "project1", "project1"); + String uuid4 = insertProperty("commonslang.one", "one", "project2", null, null, "project2", "project2"); + String uuid5 = insertProperty("user.one", "one", null, "100", "login", null, null); + String uuid6 = insertProperty("user.two", "two", null, "100", "login", null, null); + String uuid7 = insertProperty("other.one", "one", "project3", null, null, "project3", "project3"); - underTest.deleteProjectProperty("struts.one", "project1", "project1", Qualifiers.PROJECT); + underTest.deleteProjectProperty("struts.one", "project1", "project1", "project1", Qualifiers.PROJECT); assertThatPropertiesRowByUuid(uuid1) .hasKey("global.one") @@ -958,14 +1001,20 @@ public class PropertiesDaoTest { @Test public void delete_project_properties() { - String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null, null, "component"); - String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null, null, "component"); + String uuid1 = insertProperty("sonar.profile.java", "Sonar Way", "uuid1", null, null, + "component", "component"); + String uuid2 = insertProperty("sonar.profile.java", "Sonar Way", "uuid2", null, null, + "component", "component"); - String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null, null, "component"); + String uuid3 = insertProperty("sonar.profile.java", "Sonar Way", null, null, null, + "component", "component"); - String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null, null, "component"); - String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null, null, "component"); - String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null, null, "component"); + String uuid4 = insertProperty("sonar.profile.js", "Sonar Way", "uuid1", null, null, + "component", "component"); + String uuid5 = insertProperty("sonar.profile.js", "Sonar Way", "uuid2", null, null, + "component", "component"); + String uuid6 = insertProperty("sonar.profile.js", "Sonar Way", null, null, null, + "component", "component"); underTest.deleteProjectProperties("sonar.profile.java", "Sonar Way"); @@ -998,12 +1047,13 @@ public class PropertiesDaoTest { @Test public void deleteGlobalProperty() { // global - String uuid1 = insertProperty("global.key", "new_global", null, null, null, null); - String uuid2 = insertProperty("to_be_deleted", "xxx", null, null, null, null); + String uuid1 = insertProperty("global.key", "new_global", null, null, null, null, null); + String uuid2 = insertProperty("to_be_deleted", "xxx", null, null, null, null, null); // project - do not delete this project property that has the same key - String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null, null, "component"); + String uuid3 = insertProperty("to_be_deleted", "new_project", "to_be_deleted", null, null, + "component", "component"); // user - String uuid4 = insertProperty("user.key", "new_user", null, "100", "login", null); + String uuid4 = insertProperty("user.key", "new_user", null, "100", "login", null, null); underTest.deleteGlobalProperty("to_be_deleted"); @@ -1034,10 +1084,10 @@ public class PropertiesDaoTest { ComponentDto anotherProject = db.components().insertPrivateProject(); UserDto user = db.users().insertUser(); UserDto anotherUser = db.users().insertUser(); - insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name()); - insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.name()); - insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid(), anotherUser.getLogin(), project.name()); - insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid(), user.getLogin(), anotherProject.name()); + insertProperty("KEY_11", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.getKey(), project.name()); + insertProperty("KEY_12", "VALUE", project.uuid(), user.getUuid(), user.getLogin(), project.getKey(), project.name()); + insertProperty("KEY_11", "VALUE", project.uuid(), anotherUser.getUuid(), anotherUser.getLogin(), project.getKey(), project.name()); + insertProperty("KEY_11", "VALUE", anotherProject.uuid(), user.getUuid(), user.getLogin(), anotherProject.getKey(), anotherProject.name()); underTest.deleteByUser(session, user.getUuid(), user.getLogin()); @@ -1054,10 +1104,10 @@ public class PropertiesDaoTest { ComponentDto anotherProject = db.components().insertPrivateProject(); UserDto user = db.users().insertUser(); UserDto anotherUser = db.users().insertUser(); - insertProperty("KEY_11", user.getLogin(), project.uuid(), null, null, project.name()); - insertProperty("KEY_12", user.getLogin(), project.uuid(), null, null, project.name()); - insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null, null, project.name()); - insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null, null, anotherProject.name()); + insertProperty("KEY_11", user.getLogin(), project.uuid(), null, null, project.getKey(), project.name()); + insertProperty("KEY_12", user.getLogin(), project.uuid(), null, null, project.getKey(), project.name()); + insertProperty("KEY_11", anotherUser.getLogin(), project.uuid(), null, null, project.getKey(), project.name()); + insertProperty("KEY_11", user.getLogin(), anotherProject.uuid(), null, null, anotherProject.getKey(), anotherProject.name()); underTest.deleteByMatchingLogin(session, user.getLogin(), newArrayList("KEY_11", "KEY_12")); @@ -1072,14 +1122,14 @@ public class PropertiesDaoTest { public void delete_by_key_and_value() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); - insertProperty("KEY", "VALUE", null, null, null, null); - insertProperty("KEY", "VALUE", project.uuid(), null, null, project.name()); - insertProperty("KEY", "VALUE", null, "100", "login", null); - insertProperty("KEY", "VALUE", project.uuid(), "100", "login", project.name()); - insertProperty("KEY", "VALUE", anotherProject.uuid(), null, null, anotherProject.name()); + insertProperty("KEY", "VALUE", null, null, null, null, null); + insertProperty("KEY", "VALUE", project.uuid(), null, null, project.getKey(), project.name()); + insertProperty("KEY", "VALUE", null, "100", "login", null, null); + insertProperty("KEY", "VALUE", project.uuid(), "100", "login", project.getKey(), project.name()); + insertProperty("KEY", "VALUE", anotherProject.uuid(), null, null, anotherProject.getKey(), anotherProject.name()); // Should not be removed - insertProperty("KEY", "ANOTHER_VALUE", null, null, null, null); - insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100", "login", project.name()); + insertProperty("KEY", "ANOTHER_VALUE", null, null, null, null, null); + insertProperty("ANOTHER_KEY", "VALUE", project.uuid(), "100", "login", project.getKey(), project.name()); underTest.deleteByKeyAndValue(session, "KEY", "VALUE"); db.commit(); @@ -1127,7 +1177,7 @@ public class PropertiesDaoTest { @Test public void saveGlobalProperties_delete_and_insert_new_value_when_property_exists_in_db() { - String uuid = insertProperty("to_be_updated", "old_value", null, null, null, null); + String uuid = insertProperty("to_be_updated", "old_value", null, null, null, null, null); underTest.saveGlobalProperties(ImmutableMap.of("to_be_updated", "new value")); @@ -1153,12 +1203,12 @@ public class PropertiesDaoTest { @Test public void renamePropertyKey_updates_global_component_and_user_properties() { - String uuid1 = insertProperty("foo", "bar", null, null, null, null); - String uuid2 = insertProperty("old_name", "doc1", null, null, null, null); - String uuid3 = insertProperty("old_name", "doc2", "15", null, null, "component"); - String uuid4 = insertProperty("old_name", "doc3", "16", null, null, "component"); - String uuid5 = insertProperty("old_name", "doc4", null, "100", "login", null); - String uuid6 = insertProperty("old_name", "doc5", null, "101", "login", null); + String uuid1 = insertProperty("foo", "bar", null, null, null, null, null); + String uuid2 = insertProperty("old_name", "doc1", null, null, null, null, null); + String uuid3 = insertProperty("old_name", "doc2", "15", null, null, "component", "component"); + String uuid4 = insertProperty("old_name", "doc3", "16", null, null, "component", "component"); + String uuid5 = insertProperty("old_name", "doc4", null, "100", "login", null, null); + String uuid6 = insertProperty("old_name", "doc5", null, "101", "login", null, null); underTest.renamePropertyKey("old_name", "new_name"); @@ -1202,7 +1252,7 @@ public class PropertiesDaoTest { @Test public void rename_to_same_key_has_no_effect() { - String uuid = insertProperty("foo", "bar", null, null, null, null); + String uuid = insertProperty("foo", "bar", null, null, null, null,null); assertThatPropertiesRowByUuid(uuid) .hasCreatedAt(INITIAL_DATE); @@ -1238,22 +1288,23 @@ public class PropertiesDaoTest { return null; } - private void insertProperties(@Nullable String userLogin, @Nullable String projectName, PropertyDto... properties) { + private void insertProperties(@Nullable String userLogin, @Nullable String projectKey, + @Nullable String projectName, PropertyDto... properties) { for (PropertyDto propertyDto : properties) { - underTest.saveProperty(session, propertyDto, userLogin, projectName, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, userLogin, projectKey, projectName, Qualifiers.PROJECT); } session.commit(); } private String insertProperty(String key, @Nullable String value, @Nullable String componentUuid, @Nullable String userUuid, - @Nullable String userLogin, @Nullable String projectName) { + @Nullable String userLogin, @Nullable String projectKey, @Nullable String projectName) { clearInvocations(auditPersister); PropertyDto dto = new PropertyDto().setKey(key) .setComponentUuid(componentUuid) .setUserUuid(userUuid) .setValue(value); boolean isNew = session.getMapper(PropertiesMapper.class).selectByKey(dto) == null; - db.properties().insertProperty(dto, projectName, Qualifiers.PROJECT, userLogin); + db.properties().insertProperty(dto, projectKey, projectName, Qualifiers.PROJECT, userLogin); if (isNew) { verify(auditPersister).addProperty(any(), any(), anyBoolean()); } else { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java index e430e2fa07b..7e83aa2bdc2 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoWithPersisterTest.java @@ -52,6 +52,7 @@ import static org.mockito.Mockito.when; public class PropertiesDaoWithPersisterTest { private static final String KEY = "key"; private static final String ANOTHER_KEY = "another_key"; + private static final String PROJECT_KEY = "project_key"; private static final String PROJECT_NAME = "project_name"; private static final String PROJECT_UUID = "project_uuid"; private static final String SECURED_KEY = "key.secured"; @@ -123,7 +124,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister).isTrackedProperty(KEY); verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false)); @@ -131,9 +132,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(), - USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME, "project"); + USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "project"); assertThat(newValue.toString()).contains("componentUuid"); } @@ -142,7 +144,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, "app-name", Qualifiers.APP); + underTest.saveProperty(session, propertyDto, USER_LOGIN, "app-key", "app-name", Qualifiers.APP); verify(auditPersister).isTrackedProperty(KEY); verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false)); @@ -150,9 +152,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(), - USER_LOGIN, propertyDto.getComponentUuid(), "app-name", "application"); + USER_LOGIN, propertyDto.getComponentUuid(), "app-key", "app-name", "application"); assertThat(newValue.toString()) .contains("componentUuid"); } @@ -162,7 +165,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, "portfolio-name", Qualifiers.VIEW); + underTest.saveProperty(session, propertyDto, USER_LOGIN, "portfolio-key", "portfolio-name", Qualifiers.VIEW); verify(auditPersister).isTrackedProperty(KEY); verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false)); @@ -170,9 +173,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(), - USER_LOGIN, propertyDto.getComponentUuid(), "portfolio-name", "portfolio"); + USER_LOGIN, propertyDto.getComponentUuid(), "portfolio-key", "portfolio-name", "portfolio"); assertThat(newValue.toString()) .contains("componentUuid"); } @@ -182,7 +186,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(SECURED_KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(SECURED_KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister).isTrackedProperty(SECURED_KEY); verify(auditPersister).addProperty(any(), newValueCaptor.capture(), eq(false)); @@ -190,9 +194,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName, PropertyNewValue::getQualifier) .containsExactly(propertyDto.getKey(), null, propertyDto.getUserUuid(), - USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME, "project"); + USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME, "project"); assertThat(newValue.toString()).contains("componentUuid"); } @@ -201,7 +206,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyQuery query = getPropertyQuery(KEY); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); underTest.deleteByQuery(session, query); @@ -211,9 +216,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(query.key(), null, query.userUuid(), - null, query.componentUuid(), null); + null, query.componentUuid(), null, null); assertThat(newValue.toString()).doesNotContain("userLogin"); } @@ -231,7 +237,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(false); PropertyQuery query = getPropertyQuery(KEY); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); underTest.deleteByQuery(session, query); @@ -243,9 +249,9 @@ public class PropertiesDaoWithPersisterTest { public void deleteTrackedPropertyIsPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null); + underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null, null); - underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister, times(2)).isTrackedProperty(KEY); verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false)); @@ -253,9 +259,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(propertyDto.getKey(), propertyDto.getValue(), propertyDto.getUserUuid(), - USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_NAME); + USER_LOGIN, propertyDto.getComponentUuid(), PROJECT_KEY, PROJECT_NAME); assertThat(newValue.toString()).contains("userLogin"); } @@ -263,7 +270,7 @@ public class PropertiesDaoWithPersisterTest { public void deleteTrackedPropertyWithoutAffectedRowsIsNotPersisted() { PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verifyNoInteractions(auditPersister); } @@ -272,9 +279,9 @@ public class PropertiesDaoWithPersisterTest { public void deleteNotTrackedPropertyIsNotPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(false); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); - underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister, times(2)).isTrackedProperty(KEY); verifyNoMoreInteractions(auditPersister); @@ -286,7 +293,7 @@ public class PropertiesDaoWithPersisterTest { PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, null); underTest.saveProperty(propertyDto); - underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME, Qualifiers.PROJECT); + underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister, times(2)).isTrackedProperty(KEY); verify(auditPersister).deleteProperty(any(), newValueCaptor.capture(), eq(false)); @@ -294,15 +301,16 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(KEY, null, null, - null, PROJECT_UUID, PROJECT_NAME); + null, PROJECT_UUID, PROJECT_KEY, PROJECT_NAME); assertThat(newValue.toString()).doesNotContain("userLogin"); } @Test public void deleteTrackedProjectPropertyWithoutAffectedRowsIsNotPersisted() { - underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_NAME, Qualifiers.PROJECT); + underTest.deleteProjectProperty(KEY, PROJECT_UUID, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verifyNoInteractions(auditPersister); } @@ -311,9 +319,9 @@ public class PropertiesDaoWithPersisterTest { public void deleteNotTrackedProjectPropertyIsNotPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(false); PropertyDto propertyDto = getPropertyDto(KEY, PROJECT_UUID, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.saveProperty(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); - underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_NAME, Qualifiers.PROJECT); + underTest.delete(session, propertyDto, USER_LOGIN, PROJECT_KEY, PROJECT_NAME, Qualifiers.PROJECT); verify(auditPersister, times(2)).isTrackedProperty(KEY); verifyNoMoreInteractions(auditPersister); @@ -333,8 +341,9 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) - .containsExactly(KEY, VALUE, null, + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) + .containsExactly(KEY, VALUE, null, null, null, null, null); assertThat(newValue.toString()).doesNotContain("projectUuid"); } @@ -362,7 +371,7 @@ public class PropertiesDaoWithPersisterTest { public void deleteTrackedGlobalPropertyIsPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, null, null); - underTest.saveProperty(session, propertyDto, null, null, null); + underTest.saveProperty(session, propertyDto, null, null, null, null); underTest.deleteGlobalProperty(KEY, session); @@ -372,8 +381,9 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) - .containsExactly(KEY, null, null, + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) + .containsExactly(KEY, null, null, null, null, null, null); assertThat(newValue.toString()).doesNotContain("projectUuid"); } @@ -389,7 +399,7 @@ public class PropertiesDaoWithPersisterTest { public void deleteNotTrackedGlobalPropertyIsNotPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(false); PropertyDto propertyDto = getPropertyDto(KEY, null, null); - underTest.saveProperty(session, propertyDto, null, null, null); + underTest.saveProperty(session, propertyDto, null, null, null, null); underTest.deleteGlobalProperty(KEY, session); @@ -417,9 +427,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValues.get(1)) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(SECURED_KEY, null, user.getUuid(), - user.getLogin(), null, null); + user.getLogin(), null, null, null); assertThat(newValues.get(1).toString()).doesNotContain("value"); } @@ -443,16 +454,18 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValues.get(0)) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(KEY, null, null, - user.getLogin(), null, null); + user.getLogin(), null, null, null); assertThat(newValues.get(0).toString()).contains("userLogin"); assertThat(newValues.get(1)) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(SECURED_KEY, null, null, - user.getLogin(), null, null); + user.getLogin(), null, null, null); assertThat(newValues.get(1).toString()).doesNotContain("value"); } @@ -468,7 +481,7 @@ public class PropertiesDaoWithPersisterTest { when(auditPersister.isTrackedProperty(KEY)).thenReturn(true); PropertyDto propertyDto = getPropertyDto(KEY, null, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null); + underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null, null); underTest.deleteByKeyAndValue(session, KEY, VALUE); verify(auditPersister, times(2)).isTrackedProperty(KEY); @@ -477,9 +490,10 @@ public class PropertiesDaoWithPersisterTest { assertThat(newValue) .extracting(PropertyNewValue::getPropertyKey, PropertyNewValue::getPropertyValue, PropertyNewValue::getUserUuid, PropertyNewValue::getUserLogin, - PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentName) + PropertyNewValue::getComponentUuid, PropertyNewValue::getComponentKey, + PropertyNewValue::getComponentName) .containsExactly(KEY, VALUE, null, - null, null, null); + null, null, null, null); assertThat(newValue.toString()).doesNotContain("projectUuid"); } @@ -494,7 +508,7 @@ public class PropertiesDaoWithPersisterTest { public void deleteNotTrackedPropertyByKeyAndValueIsNotPersisted() { when(auditPersister.isTrackedProperty(KEY)).thenReturn(false); PropertyDto propertyDto = getPropertyDto(KEY, null, USER_UUID); - underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null); + underTest.saveProperty(session, propertyDto, USER_LOGIN, null, null, null); underTest.deleteByKeyAndValue(session, KEY, VALUE); @@ -542,9 +556,9 @@ public class PropertiesDaoWithPersisterTest { .setComponentUuid(project.uuid()) .setUserUuid(user.getUuid()) .setValue(value); - db.properties().insertProperty(dto1, project.name(), project.qualifier(), user.getLogin()); - db.properties().insertProperty(dto2, project.name(), project.qualifier(), user.getLogin()); - db.properties().insertProperty(dto3, project.name(), project.qualifier(), user.getLogin()); + db.properties().insertProperty(dto1, project.getKey(), project.name(), project.qualifier(), user.getLogin()); + db.properties().insertProperty(dto2, project.getKey(), project.name(), project.qualifier(), user.getLogin()); + db.properties().insertProperty(dto3, project.getKey(), project.name(), project.qualifier(), user.getLogin()); return user; } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 6aa13a36cb0..2e27954c644 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -1646,7 +1646,7 @@ public class PurgeDaoTest { .setKey(randomAlphabetic(3)) .setValue(randomAlphabetic(3)) .setComponentUuid(componentDto.uuid()), - componentDto.name(), componentDto.qualifier(), null)); + componentDto.getKey(), componentDto.name(), componentDto.qualifier(), null)); } private void insertPropertyFor(Collection<BranchDto> branches) { @@ -1654,7 +1654,7 @@ public class PurgeDaoTest { .setKey(randomAlphabetic(3)) .setValue(randomAlphabetic(3)) .setComponentUuid(branchDto.getUuid()), - branchDto.getKey(), null,null)); + null, branchDto.getKey(), null,null)); } private Stream<String> getComponentUuidsOfMeasures() { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoWithAuditTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoWithAuditTest.java index 22d7cf8bfc1..0b37df85ebc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoWithAuditTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoWithAuditTest.java @@ -62,7 +62,7 @@ public class PurgeDaoWithAuditTest { verify(auditPersister).deleteComponent(any(DbSession.class), newValueCaptor.capture(), eq(project.qualifier())); ComponentNewValue componentNewValue = newValueCaptor.getValue(); assertThat(componentNewValue) - .extracting(ComponentNewValue::getComponentUuid, ComponentNewValue::getComponentName, ComponentNewValue::getKey, + .extracting(ComponentNewValue::getComponentUuid, ComponentNewValue::getComponentName, ComponentNewValue::getComponentKey, ComponentNewValue::getQualifier) .containsExactly(project.uuid(), project.name(), project.getKey(), "project"); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java index aed697b2e19..fdc7d8111f0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java @@ -82,7 +82,7 @@ public class WebhookDaoTest { .setUrl("URL_1") .setSecret("a_secret"); - underTest.insert(dbSession, dto, null); + underTest.insert(dbSession, dto, null, null); WebhookDto stored = selectByUuid(dto.getUuid()); @@ -104,7 +104,7 @@ public class WebhookDaoTest { .setProjectUuid("UUID_2") .setSecret("a_secret"); - underTest.insert(dbSession, dto, "project_name"); + underTest.insert(dbSession, dto, "project_key", "project_name"); WebhookDto reloaded = selectByUuid(dto.getUuid()); @@ -125,7 +125,7 @@ public class WebhookDaoTest { .setName("a-fancy-webhook") .setUrl("http://www.fancy-webhook.io") .setSecret(null), - null); + null, null); Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid()); assertThat(optionalResult).isPresent(); @@ -147,7 +147,7 @@ public class WebhookDaoTest { .setName("a-fancy-webhook") .setUrl("http://www.fancy-webhook.io") .setSecret("a_new_secret"), - null); + null, null); Optional<WebhookDto> optionalResult = underTest.selectByUuid(dbSession, dto.getUuid()); assertThat(optionalResult).isPresent(); @@ -192,7 +192,7 @@ public class WebhookDaoTest { .setName("NAME_1") .setUrl("URL_1"); - underTest.insert(dbSession, dto, null); + underTest.insert(dbSession, dto, null, null); Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid()); assertThat(reloaded).isPresent(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java index 97dc844b750..47b0f29498d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoWithPersisterTest.java @@ -60,7 +60,7 @@ public class WebhookDaoWithPersisterTest { .setUrl("URL_1") .setSecret("a_secret"); - underTest.insert(dbSession, dto, null); + underTest.insert(dbSession, dto, null, null); verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture()); WebhookNewValue newValue = newValueCaptor.getValue(); @@ -79,14 +79,16 @@ public class WebhookDaoWithPersisterTest { .setProjectUuid("UUID_2") .setSecret("a_secret"); - underTest.insert(dbSession, dto, "project_name"); + underTest.insert(dbSession, dto, "project_key", "project_name"); verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture()); WebhookNewValue newValue = newValueCaptor.getValue(); assertThat(newValue) - .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName) - .containsExactly(dto.getUuid(), dto.getName(), dto.getProjectUuid(), "project_name"); - assertThat(newValue).hasToString("{\"webhookUuid\": \"UUID_1\", \"name\": \"NAME_1\", \"url\": \"URL_1\", \"projectUuid\": \"UUID_2\", \"projectName\": \"project_name\" }"); + .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid, + WebhookNewValue::getProjectKey, WebhookNewValue::getProjectName) + .containsExactly(dto.getUuid(), dto.getName(), dto.getProjectUuid(), "project_key", "project_name"); + assertThat(newValue).hasToString("{\"webhookUuid\": \"UUID_1\", \"name\": \"NAME_1\", \"url\": \"URL_1\", " + + "\"projectUuid\": \"UUID_2\", \"projectKey\": \"project_key\", \"projectName\": \"project_name\" }"); } @Test @@ -97,7 +99,7 @@ public class WebhookDaoWithPersisterTest { .setUrl("http://www.fancy-webhook.io") .setSecret(null); - underTest.update(dbSession, dto, null); + underTest.update(dbSession, dto, null, null); verify(auditPersister).updateWebhook(eq(dbSession), newValueCaptor.capture()); WebhookNewValue newValue = newValueCaptor.getValue(); @@ -115,19 +117,22 @@ public class WebhookDaoWithPersisterTest { .setUrl("http://www.fancy-webhook.io") .setSecret(null); - underTest.update(dbSession, dto, "project"); + underTest.update(dbSession, dto, "project-key", "project-name"); verify(auditPersister).updateWebhook(eq(dbSession), newValueCaptor.capture()); WebhookNewValue newValue = newValueCaptor.getValue(); assertThat(newValue) - .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl) - .containsExactly(dto.getUuid(), dto.getName(), dto.getUrl()); - assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() +"\", \"name\": \"a-fancy-webhook\", \"url\": \"http://www.fancy-webhook.io\", \"projectName\": \"project\" }"); + .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl, + WebhookNewValue::getProjectKey, WebhookNewValue::getProjectName) + .containsExactly(dto.getUuid(), dto.getName(), dto.getUrl(), "project-key", "project-name"); + assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() +"\", \"name\": \"a-fancy-webhook\", " + + "\"url\": \"http://www.fancy-webhook.io\", \"projectKey\": \"project-key\", \"projectName\": \"project-name\" }"); } @Test public void deleteProjectWebhooksIsPersisted() { - ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(p -> p.setUuid("puuid").setName("pname")); + ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(p -> + p.setUuid("puuid").setName("pname").setDbKey("pkey")); webhookDbTester.insertWebhook(projectDto); underTest.deleteByProject(dbSession, projectDto); @@ -135,9 +140,10 @@ public class WebhookDaoWithPersisterTest { verify(auditPersister).deleteWebhook(eq(dbSession), newValueCaptor.capture()); WebhookNewValue newValue = newValueCaptor.getValue(); assertThat(newValue) - .extracting(WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName) - .containsExactly(projectDto.getUuid(), projectDto.getName()); - assertThat(newValue).hasToString("{\"projectUuid\": \"puuid\", \"projectName\": \"pname\" }"); + .extracting(WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectKey, WebhookNewValue::getProjectName) + .containsExactly(projectDto.getUuid(), projectDto.getKey(), projectDto.getName()); + assertThat(newValue).hasToString("{\"projectUuid\": \"puuid\", " + + "\"projectKey\": \"pkey\", \"projectName\": \"pname\" }"); } @Test diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java index e271b82a78c..c1eee3e00f0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDeliveryDaoTest.java @@ -114,7 +114,7 @@ public class WebhookDeliveryDaoTest { @Test public void selectByWebhookUuid_returns_records_ordered_by_date() { - WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME"); + WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME"); WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE); WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW); WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW); @@ -129,7 +129,7 @@ public class WebhookDeliveryDaoTest { @Test public void selectByWebhookUuid_returns_records_according_to_pagination() { - WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME"); + WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME"); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L)); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L)); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L)); @@ -144,11 +144,11 @@ public class WebhookDeliveryDaoTest { @Test public void selectLatestDelivery_of_a_webhook() { - WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME"); + WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME"); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE)); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW)); - WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME"); + WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME"); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE)); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW)); @@ -197,7 +197,7 @@ public class WebhookDeliveryDaoTest { @Test public void deleteByWebhook() { - WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_NAME"); + WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME"); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L)); underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L)); diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java index 10e245aaa8a..906d9099521 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/almsettings/AlmSettingsDbTester.java @@ -74,57 +74,57 @@ public class AlmSettingsDbTester { public final ProjectAlmSettingDto insertGitHubProjectAlmSetting(AlmSettingDto githubAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { return insertProjectAlmSetting(newGithubProjectAlmSettingDto(githubAlmSetting, project), githubAlmSetting.getKey(), - project.getName(), populators); + project.getName(), project.getKey(), populators); } public ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) { return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(), - project.getName()); + project.getName(), project.getKey()); } public ProjectAlmSettingDto insertAzureMonoRepoProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project) { return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(), - project.getName(), d -> d.setMonorepo(true)); + project.getName(), project.getKey(), d -> d.setMonorepo(true)); } public ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project) { return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(), - project.getName()); + project.getName(), project.getKey()); } @SafeVarargs public final ProjectAlmSettingDto insertAzureProjectAlmSetting(AlmSettingDto azureAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { return insertProjectAlmSetting(newAzureProjectAlmSettingDto(azureAlmSetting, project), azureAlmSetting.getKey(), - project.getName(), populators); + project.getName(), project.getKey(), populators); } @SafeVarargs public final ProjectAlmSettingDto insertGitlabProjectAlmSetting(AlmSettingDto gitlabAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { return insertProjectAlmSetting(newGitlabProjectAlmSettingDto(gitlabAlmSetting, project), gitlabAlmSetting.getKey(), - project.getName(), populators); + project.getName(), project.getKey(), populators); } @SafeVarargs public final ProjectAlmSettingDto insertBitbucketCloudProjectAlmSetting(AlmSettingDto bbCloudAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { return insertProjectAlmSetting(newBitbucketCloudProjectAlmSettingDto(bbCloudAlmSetting, project), bbCloudAlmSetting.getKey(), - project.getName(), populators); + project.getName(), project.getKey(), populators); } @SafeVarargs public final ProjectAlmSettingDto insertBitbucketProjectAlmSetting(AlmSettingDto bitbucketAlmSetting, ProjectDto project, Consumer<ProjectAlmSettingDto>... populators) { return insertProjectAlmSetting(newBitbucketProjectAlmSettingDto(bitbucketAlmSetting, project), - bitbucketAlmSetting.getKey(), project.getName(), populators); + bitbucketAlmSetting.getKey(), project.getName(), project.getKey(), populators); } @SafeVarargs private final ProjectAlmSettingDto insertProjectAlmSetting(ProjectAlmSettingDto dto, String key, String projectName, - Consumer<ProjectAlmSettingDto>... populators) { + String projectKey, Consumer<ProjectAlmSettingDto>... populators) { stream(populators).forEach(p -> p.accept(dto)); - db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto, key, projectName); + db.getDbClient().projectAlmSettingDao().insertOrUpdate(db.getSession(), dto, key, projectName, projectKey); db.commit(); return dto; } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java index fd75fb40227..66887618dc3 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/favorite/FavoriteDbTester.java @@ -43,7 +43,7 @@ public class FavoriteDbTester { .setKey(PROP_FAVORITE_KEY) .setUserUuid(userUuid) .setComponentUuid(componentDto.uuid()), - userLogin, componentDto.name(), componentDto.qualifier()); + userLogin, componentDto.getKey(), componentDto.name(), componentDto.qualifier()); dbSession.commit(); } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java index aac7f1fdbf4..8626f498e34 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/property/PropertyDbTester.java @@ -46,23 +46,24 @@ public class PropertyDbTester { this.dbSession = db.getSession(); } - public PropertyDto insertProperty(PropertyDto property, @Nullable String componentName, @Nullable String qualifier, - @Nullable String userLogin) { - dbClient.propertiesDao().saveProperty(dbSession, property, userLogin, qualifier, componentName); + public PropertyDto insertProperty(PropertyDto property, @Nullable String componentKey, + @Nullable String componentName, @Nullable String qualifier, @Nullable String userLogin) { + dbClient.propertiesDao().saveProperty(dbSession, property, userLogin, componentKey, componentName, qualifier); db.commit(); return property; } - public void insertProperties(@Nullable String userLogin, @Nullable String projectName, @Nullable String qualifier, + public void insertProperties(@Nullable String userLogin, @Nullable String projectKey, + @Nullable String projectName, @Nullable String qualifier, PropertyDto... properties) { - insertProperties(asList(properties), userLogin, qualifier, projectName); + insertProperties(asList(properties), userLogin, projectKey, projectName, qualifier); } - public void insertProperties(List<PropertyDto> properties, @Nullable String userLogin, @Nullable String projectName, - @Nullable String qualifier) { + public void insertProperties(List<PropertyDto> properties, @Nullable String userLogin, @Nullable String projectKey, + @Nullable String projectName, @Nullable String qualifier) { for (PropertyDto propertyDto : properties) { - dbClient.propertiesDao().saveProperty(dbSession, propertyDto, userLogin, projectName, qualifier); + dbClient.propertiesDao().saveProperty(dbSession, propertyDto, userLogin, projectKey, projectName, qualifier); } dbSession.commit(); } @@ -89,9 +90,10 @@ public class PropertyDbTester { } else { propertyDtos.add(newGlobalPropertyDto().setKey(settingBaseKey).setValue(idsValue)); } + String componentKey = componentDto == null ? null : componentDto.getKey(); String componentName = componentDto == null ? null : componentDto.name(); String qualififer = componentDto == null ? null : componentDto.qualifier(); - insertProperties(propertyDtos, null, componentName, qualififer); + insertProperties(propertyDtos, null, componentKey, componentName, qualififer); } public PropertyDbTester verifyInternal(String key, @Nullable String expectedValue) { diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDbTester.java index 474e2b014f3..8b0c96f6173 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/webhook/WebhookDbTester.java @@ -37,16 +37,16 @@ public class WebhookDbTester { } public WebhookDto insertGlobalWebhook() { - return insert(newGlobalWebhook(), null); + return insert(newGlobalWebhook(), null, null); } public WebhookDto insertWebhook(ProjectDto project) { - return insert(newWebhook(project), project.getName()); + return insert(newWebhook(project), project.getKey(), project.getName()); } - public WebhookDto insert(WebhookDto dto, @Nullable String projectName) { + public WebhookDto insert(WebhookDto dto, @Nullable String projectKey, @Nullable String projectName) { DbSession dbSession = dbTester.getSession(); - dbTester.getDbClient().webhookDao().insert(dbSession, dto, projectName); + dbTester.getDbClient().webhookDao().insert(dbSession, dto, projectKey, projectName); dbSession.commit(); return dto; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java index e5abb245540..dfe0318f96f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/favorite/FavoriteUpdater.java @@ -63,7 +63,7 @@ public class FavoriteUpdater { .setComponentUuid(componentDto.uuid()) .setUserUuid(userUuid), userLogin, - componentDto.name(), componentDto.qualifier()); + componentDto.getKey(), componentDto.name(), componentDto.qualifier()); } /** @@ -80,7 +80,7 @@ public class FavoriteUpdater { .setKey(PROP_FAVORITE_KEY) .setComponentUuid(component.uuid()) .setUserUuid(userUuid), - userLogin, component.name(), component.qualifier()); + userLogin, component.getKey(), component.name(), component.qualifier()); checkArgument(result == 1, "Component '%s' is not a favorite", component.getDbKey()); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java index 74a37ad19a6..aa59b1782f4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java @@ -102,7 +102,7 @@ public class StartupMetadataProviderTest { private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) { dbTester.properties().insertProperty(new PropertyDto().setKey(CoreProperties.SERVER_STARTTIME).setValue(formatDateTime(A_DATE)), - null, null, null); + null, null,null, null); when(webServer.isStartupLeader()).thenReturn(isStartupLeader); StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/AsynchronousWebHooksImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/AsynchronousWebHooksImplTest.java index 602ebb5a064..2275df91596 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/AsynchronousWebHooksImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/AsynchronousWebHooksImplTest.java @@ -63,8 +63,8 @@ public class AsynchronousWebHooksImplTest { @Test public void send_global_webhooks() { ComponentDto project = componentDbTester.insertPrivateProject(); - webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null); - webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null); + webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null, null); + webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null, null); caller.enqueueSuccess(NOW, 200, 1_234); caller.enqueueFailure(NOW, new IOException("Fail to connect")); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java index 047e1ab047e..1a09af24652 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/SynchronousWebHooksImplTest.java @@ -74,7 +74,7 @@ public class SynchronousWebHooksImplTest { @Test public void isEnabled_returns_true_if_one_valid_global_webhook() { ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(); - webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName()); + webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getKey(), projectDto.getName()); assertThat(underTest.isEnabled(projectDto)).isTrue(); } @@ -82,7 +82,7 @@ public class SynchronousWebHooksImplTest { @Test public void isEnabled_returns_true_if_one_valid_project_webhook() { ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(); - webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName()); + webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getKey(), projectDto.getName()); assertThat(underTest.isEnabled(projectDto)).isTrue(); } @@ -113,8 +113,8 @@ public class SynchronousWebHooksImplTest { @Test public void send_global_webhooks() { ComponentDto componentDto = componentDbTester.insertPrivateProject(); - webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null); - webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null); + webhookDbTester.insert(newGlobalWebhook().setName("First").setUrl("http://url1"), null, null); + webhookDbTester.insert(newGlobalWebhook().setName("Second").setUrl("http://url2"), null, null); caller.enqueueSuccess(NOW, 200, 1_234); caller.enqueueFailure(NOW, new IOException("Fail to connect")); @@ -131,7 +131,7 @@ public class SynchronousWebHooksImplTest { @Test public void send_project_webhooks() { ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(); - webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getName()); + webhookDbTester.insert(newWebhook(projectDto).setName("First").setUrl("http://url1"), projectDto.getKey(), projectDto.getName()); caller.enqueueSuccess(NOW, 200, 1_234); underTest.sendProjectAnalysisUpdate(new WebHooks.Analysis(projectDto.getUuid(), "1", "#1"), () -> mock, taskStatistics); @@ -146,11 +146,11 @@ public class SynchronousWebHooksImplTest { @Test public void send_global_and_project_webhooks() { ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(); - webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"), projectDto.getName()); - webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"), projectDto.getName()); - webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"), null); - webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"), null); - webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"), null); + webhookDbTester.insert(newWebhook(projectDto).setName("1First").setUrl("http://url1"), projectDto.getKey(), projectDto.getName()); + webhookDbTester.insert(newWebhook(projectDto).setName("2Second").setUrl("http://url2"), projectDto.getKey(), projectDto.getName()); + webhookDbTester.insert(newGlobalWebhook().setName("3Third").setUrl("http://url3"), null, null); + webhookDbTester.insert(newGlobalWebhook().setName("4Fourth").setUrl("http://url4"), null,null); + webhookDbTester.insert(newGlobalWebhook().setName("5Fifth").setUrl("http://url5"), null,null); caller.enqueueSuccess(NOW, 200, 1_234); caller.enqueueFailure(NOW, new IOException("Fail to connect 1")); caller.enqueueFailure(NOW, new IOException("Fail to connect 2")); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java index 178ec824b7a..582c4e35a82 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/plugins/PluginConsentVerifier.java @@ -54,7 +54,7 @@ public class PluginConsentVerifier implements Startable { if (hasExternalPlugins && NOT_ACCEPTED == PluginRiskConsent.valueOf(property.getValue())) { addWarningInSonarDotLog(); property.setValue(REQUIRED.name()); - dbClient.propertiesDao().saveProperty(session, property, null, null, null); + dbClient.propertiesDao().saveProperty(session, property, null, null, null, null); session.commit(); } else if (!hasExternalPlugins && REQUIRED == PluginRiskConsent.valueOf(property.getValue())) { dbClient.propertiesDao().deleteGlobalProperty(PLUGINS_RISK_CONSENT, session); diff --git a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectDefaultVisibility.java b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectDefaultVisibility.java index 07d0d37da1c..0bcb0010a03 100644 --- a/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectDefaultVisibility.java +++ b/server/sonar-webserver-api/src/main/java/org/sonar/server/project/ProjectDefaultVisibility.java @@ -46,6 +46,6 @@ public class ProjectDefaultVisibility { public void set(DbSession dbSession, Visibility visibility) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto() .setKey(PROJECTS_DEFAULT_VISIBILITY_PROPERTY_NAME) - .setValue(visibility.getLabel()), null, null, null); + .setValue(visibility.getLabel()), null, null, null, null); } } diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java index 9440c0225da..dae4966e208 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserUpdaterUpdateTest.java @@ -233,12 +233,12 @@ public class UserUpdaterUpdateTest { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); - db.properties().insertProperties(oldUser.getLogin(), project1.name(), project1.qualifier(), + db.properties().insertProperties(oldUser.getLogin(), project1.getKey(), project1.name(), project1.qualifier(), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project1.uuid())); - db.properties().insertProperties(oldUser.getLogin(), project2.name(), project2.qualifier(), + db.properties().insertProperties(oldUser.getLogin(), project2.getKey(), project2.name(), project2.qualifier(), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue(oldUser.getLogin()).setComponentUuid(project2.uuid())); - db.properties().insertProperties(oldUser.getLogin(), anotherProject.name(), anotherProject.qualifier(), + db.properties().insertProperties(oldUser.getLogin(), anotherProject.getKey(),anotherProject.name(), anotherProject.qualifier(), new PropertyDto().setKey(DEFAULT_ISSUE_ASSIGNEE).setValue("another login").setComponentUuid(anotherProject.uuid())); userIndexer.indexAll(); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/PersistentSettings.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/PersistentSettings.java index cd50694adce..485cb62d295 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/PersistentSettings.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/PersistentSettings.java @@ -72,7 +72,7 @@ public class PersistentSettings { if (value == null) { dbClient.propertiesDao().deleteGlobalProperty(key, dbSession); } else { - dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value), null, null, null); + dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(value), null, null, null, null); } // refresh the cache of settings delegate.setProperty(key, value); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java index f87fa6f23c2..10047e05c1b 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/serverid/ServerIdManager.java @@ -140,7 +140,7 @@ public class ServerIdManager implements Startable { private void persistServerId(DbSession dbSession, ServerId serverId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(serverId.toString()), - null, null, null); + null, null, null, null); } private void persistChecksum(DbSession dbSession, String checksump) { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java index 97d28f89917..8505afc474b 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/serverid/ServerIdManagerTest.java @@ -345,7 +345,7 @@ public class ServerIdManagerTest { private void insertServerId(String serverId) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(serverId), - null, null, null); + null, null, null, null); dbSession.commit(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectAction.java index 9fbc93982bd..412537d72f2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectAction.java @@ -148,7 +148,8 @@ public class ImportAzureProjectAction implements AlmIntegrationsWsAction { .setAlmSlug(repo.getProject().getName()) .setProjectUuid(componentDto.uuid()) .setMonorepo(false); - dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name()); + dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), + componentDto.name(), componentDto.getKey()); } @VisibleForTesting diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java index b3cb415e680..693d614cbc8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketcloud/ImportBitbucketCloudRepoAction.java @@ -144,7 +144,8 @@ public class ImportBitbucketCloudRepoAction implements AlmIntegrationsWsAction { .setAlmRepo(repo.getSlug()) .setProjectUuid(componentDto.uuid()) .setMonorepo(false); - dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name()); + dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), + componentDto.name(), componentDto.getKey()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectAction.java index 26c138ff673..f00c0c22728 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectAction.java @@ -20,6 +20,7 @@ package org.sonar.server.almintegration.ws.bitbucketserver; import java.util.Optional; +import javax.annotation.Nullable; import org.sonar.alm.client.bitbucketserver.BitbucketServerRestClient; import org.sonar.alm.client.bitbucketserver.Branch; import org.sonar.alm.client.bitbucketserver.BranchesList; @@ -47,7 +48,6 @@ import static org.sonar.server.almintegration.ws.ImportHelper.PARAM_ALM_SETTING; import static org.sonar.server.almintegration.ws.ImportHelper.toCreateResponse; import static org.sonar.server.component.NewComponent.newComponentBuilder; import static org.sonar.server.ws.WsUtils.writeProtobuf; -import javax.annotation.Nullable; public class ImportBitbucketServerProjectAction implements AlmIntegrationsWsAction { @@ -160,7 +160,8 @@ public class ImportBitbucketServerProjectAction implements AlmIntegrationsWsActi .setAlmSlug(repo.getSlug()) .setProjectUuid(componentDto.uuid()) .setMonorepo(false); - dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name()); + dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), + componentDto.name(), componentDto.getKey()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectAction.java index ce584b71a9d..46cabf89d22 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectAction.java @@ -152,6 +152,7 @@ public class ImportGithubProjectAction implements AlmIntegrationsWsAction { .setProjectUuid(componentDto.uuid()) .setSummaryCommentEnabled(true) .setMonorepo(false); - dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), componentDto.name()); + dbClient.projectAlmSettingDao().insertOrUpdate(dbSession, projectAlmSettingDto, almSettingDto.getKey(), + componentDto.name(), componentDto.getKey()); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java index 6fcfcba5f0b..ef413756565 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectAction.java @@ -130,7 +130,7 @@ public class ImportGitLabProjectAction implements AlmIntegrationsWsAction { .setAlmSlug(null) .setMonorepo(false), almSettingDto.getKey(), - componentDto.name()); + componentDto.name(), componentDto.getKey()); } private ComponentDto createProject(DbSession dbSession, Project gitlabProject, @Nullable String mainBranchName) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java index d19281c6d5c..a341ba99f75 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/NotificationUpdater.java @@ -48,6 +48,7 @@ public class NotificationUpdater { public void add(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); String projectUuid = project == null ? null : project.uuid(); + String projectKey = project == null ? null : project.getKey(); String projectName = project == null ? null : project.name(); String qualifier = project == null ? null : project.qualifier(); @@ -68,7 +69,7 @@ public class NotificationUpdater { .setUserUuid(user.getUuid()) .setValue(PROP_NOTIFICATION_VALUE) .setComponentUuid(projectUuid), - user.getLogin(), projectName, qualifier); + user.getLogin(), projectKey, projectName, qualifier); } /** @@ -77,6 +78,7 @@ public class NotificationUpdater { public void remove(DbSession dbSession, String channel, String dispatcher, UserDto user, @Nullable ComponentDto project) { String key = String.join(".", PROP_NOTIFICATION_PREFIX, dispatcher, channel); String projectUuid = project == null ? null : project.uuid(); + String projectKey = project == null ? null : project.getKey(); String projectName = project == null ? null : project.name(); String qualifier = project == null ? null : project.qualifier(); @@ -95,7 +97,7 @@ public class NotificationUpdater { .setKey(key) .setUserUuid(user.getUuid()) .setValue(PROP_NOTIFICATION_VALUE) - .setComponentUuid(projectUuid), user.getLogin(), projectName, qualifier); + .setComponentUuid(projectUuid), user.getLogin(), projectKey, projectName, qualifier); } private static Predicate<PropertyDto> notificationScope(@Nullable ComponentDto project) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java index fd5010c682c..12dad7b7e1a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java @@ -135,7 +135,8 @@ public class UpdateVisibilityAction implements ProjectsWsAction { private void setPrivateForRootComponentUuid(DbSession dbSession, ComponentDto component, boolean isPrivate) { String uuid = component.uuid(); - dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.qualifier(), component.name(), true); + dbClient.componentDao().setPrivateForRootComponentUuid(dbSession, uuid, isPrivate, component.getKey(), + component.qualifier(), component.name(), true); if (component.qualifier().equals(Qualifiers.PROJECT) || component.qualifier().equals(Qualifiers.APP)) { dbClient.projectDao().updateVisibility(dbSession, uuid, isPrivate); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java index 52237b4a733..c6e30f5db03 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SetAction.java @@ -144,6 +144,7 @@ public class SetAction implements SettingsWsAction { private void doHandle(DbSession dbSession, SetRequest request) { Optional<ComponentDto> component = searchComponent(dbSession, request); + String projectKey = component.isPresent() ? component.get().getKey() : null; String projectName = component.isPresent() ? component.get().name() : null; String qualifier = component.isPresent() ? component.get().qualifier() : null; checkPermissions(component); @@ -160,7 +161,7 @@ public class SetAction implements SettingsWsAction { validate(request); PropertyDto property = toProperty(request, component); value = property.getValue(); - dbClient.propertiesDao().saveProperty(dbSession, property, null, projectName, qualifier); + dbClient.propertiesDao().saveProperty(dbSession, property, null, projectKey, projectName, qualifier); } dbSession.commit(); @@ -177,19 +178,20 @@ public class SetAction implements SettingsWsAction { String inlinedFieldKeys = IntStream.of(fieldIds).mapToObj(String::valueOf).collect(COMMA_JOINER); String key = persistedKey(request); String componentUuid = component.isPresent() ? component.get().uuid() : null; + String componentKey = component.isPresent() ? component.get().getKey() : null; String componentName = component.isPresent() ? component.get().name() : null; String qualifier = component.isPresent() ? component.get().qualifier() : null; deleteSettings(dbSession, component, key); dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(key).setValue(inlinedFieldKeys) - .setComponentUuid(componentUuid), null, componentName, qualifier); + .setComponentUuid(componentUuid), null, componentKey, componentName, qualifier); List<String> fieldValues = request.getFieldValues(); IntStream.of(fieldIds).boxed() .flatMap(i -> readOneFieldValues(fieldValues.get(i - 1), request.getKey()).entrySet().stream() .map(entry -> new KeyValue(key + "." + i + "." + entry.getKey(), entry.getValue()))) .forEach(keyValue -> dbClient.propertiesDao().saveProperty(dbSession, toFieldProperty(keyValue, componentUuid), - null, componentName, qualifier)); + null, componentKey, componentName, qualifier)); return inlinedFieldKeys; } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java index 50ce79791d0..d92c3546d4b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/setting/ws/SettingsUpdater.java @@ -75,8 +75,8 @@ public class SettingsUpdater { private void deleteSetting(DbSession dbSession, String settingKey, Optional<ComponentDto> componentDto) { if (componentDto.isPresent()) { - dbClient.propertiesDao().deleteProjectProperty(dbSession, settingKey, componentDto.get().uuid(), componentDto.get().name(), - componentDto.get().qualifier()); + dbClient.propertiesDao().deleteProjectProperty(dbSession, settingKey, componentDto.get().uuid(), componentDto.get().getKey(), + componentDto.get().name(), componentDto.get().qualifier()); } else { dbClient.propertiesDao().deleteGlobalProperty(settingKey, dbSession); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java index ca96fd485d1..9e53dd6031b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/CreateAction.java @@ -127,7 +127,7 @@ public class CreateAction implements WebhooksWsAction { webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url); WebhookDto dto = doHandle(dbSession, projectDto, name, url, secret); String projectName = projectDto == null ? null : projectDto.getName(); - dbClient.webhookDao().insert(dbSession, dto, projectName); + dbClient.webhookDao().insert(dbSession, dto, projectKey, projectName); dbSession.commit(); writeResponse(request, response, dto); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java index 19511535d4c..35493e58c5c 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java @@ -116,10 +116,10 @@ public class UpdateAction implements WebhooksWsAction { if (projectUuid != null) { ProjectDto projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid); webhookSupport.checkPermission(projectDto); - updateWebhook(dbSession, webhookDto, name, url, secret, projectDto.getName()); + updateWebhook(dbSession, webhookDto, name, url, secret, projectDto.getKey(), projectDto.getName()); } else { webhookSupport.checkPermission(); - updateWebhook(dbSession, webhookDto, name, url, secret, null); + updateWebhook(dbSession, webhookDto, name, url, secret, null, null); } dbSession.commit(); @@ -128,12 +128,13 @@ public class UpdateAction implements WebhooksWsAction { response.noContent(); } - private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret, @Nullable String projectName) { + private void updateWebhook(DbSession dbSession, WebhookDto dto, String name, String url, @Nullable String secret, + @Nullable String projectKey, @Nullable String projectName) { dto .setName(name) .setUrl(url) .setSecret(secret); - dbClient.webhookDao().update(dbSession, dto, projectName); + dbClient.webhookDao().update(dbSession, dto, projectKey, projectName); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java index be7e7c5d219..5bbb19db0df 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/SearchProjectsActionTest.java @@ -558,7 +558,7 @@ public class SearchProjectsActionTest { Stream.of(javaProject, markDownProject).forEach(this::addFavourite); index(); - addFavourite(null, null, null); + addFavourite(null, null, null, null); SearchProjectsWsResponse result = call(request.setFilter("isFavorite")); @@ -1342,12 +1342,15 @@ public class SearchProjectsActionTest { } private void addFavourite(ComponentDto project) { - addFavourite(project.uuid(), project.name(), project.qualifier()); + addFavourite(project.uuid(), project.getKey(), + project.name(), project.qualifier()); } - private void addFavourite(@Nullable String componentUuid, @Nullable String componentName, @Nullable String qualifier) { + private void addFavourite(@Nullable String componentUuid, @Nullable String componentKey, + @Nullable String componentName, @Nullable String qualifier) { dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite") - .setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()), userSession.getLogin(), componentName, qualifier); + .setComponentUuid(componentUuid).setUserUuid(userSession.getUuid()), userSession.getLogin(), componentKey, + componentName, qualifier); dbSession.commit(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java index 111843174b1..da1439addee 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ResetActionTest.java @@ -96,7 +96,7 @@ public class ResetActionTest { public void remove_global_setting() { logInAsSystemAdministrator(); definitions.addComponent(PropertyDefinition.builder("foo").build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); executeRequestOnGlobalSetting("foo"); assertGlobalPropertyDoesNotExist("foo"); @@ -105,7 +105,7 @@ public class ResetActionTest { @Test public void remove_global_setting_even_if_not_defined() { logInAsSystemAdministrator(); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); executeRequestOnGlobalSetting("foo"); assertGlobalPropertyDoesNotExist("foo"); @@ -115,7 +115,7 @@ public class ResetActionTest { public void remove_component_setting() { logInAsProjectAdmin(); definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build()); - propertyDb.insertProperties(null, null, null, newComponentPropertyDto(project).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, null, null, null, newComponentPropertyDto(project).setKey("foo").setValue("value")); executeRequestOnProjectSetting("foo"); assertProjectPropertyDoesNotExist("foo"); @@ -124,7 +124,7 @@ public class ResetActionTest { @Test public void remove_component_setting_even_if_not_defined() { logInAsProjectAdmin(); - propertyDb.insertProperties(null, null, null, newComponentPropertyDto(project).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, null, null, null, newComponentPropertyDto(project).setKey("foo").setValue("value")); executeRequestOnProjectSetting("foo"); assertProjectPropertyDoesNotExist("foo"); @@ -134,7 +134,7 @@ public class ResetActionTest { public void remove_hidden_setting() { logInAsSystemAdministrator(); definitions.addComponent(PropertyDefinition.builder("foo").hidden().build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); executeRequestOnGlobalSetting("foo"); assertGlobalPropertyDoesNotExist("foo"); @@ -143,8 +143,10 @@ public class ResetActionTest { @Test public void ignore_project_setting_when_removing_global_setting() { logInAsSystemAdministrator(); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + newComponentPropertyDto(project).setKey("foo").setValue("value")); executeRequestOnGlobalSetting("foo"); @@ -155,8 +157,9 @@ public class ResetActionTest { @Test public void ignore_global_setting_when_removing_project_setting() { logInAsProjectAdmin(); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + newComponentPropertyDto(project).setKey("foo").setValue("value")); executeRequestOnProjectSetting("foo"); @@ -168,7 +171,7 @@ public class ResetActionTest { public void ignore_user_setting_when_removing_global_setting() { logInAsSystemAdministrator(); UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto()); - propertyDb.insertProperties(user.getLogin(), null, null, newUserPropertyDto("foo", "one", user)); + propertyDb.insertProperties(user.getLogin(), null, null, null, newUserPropertyDto("foo", "one", user)); executeRequestOnGlobalSetting("foo"); assertUserPropertyExists("foo", user); @@ -178,7 +181,7 @@ public class ResetActionTest { public void ignore_user_setting_when_removing_project_setting() { logInAsProjectAdmin(); UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto()); - propertyDb.insertProperties(user.getLogin(), null, null, newUserPropertyDto("foo", "one", user)); + propertyDb.insertProperties(user.getLogin(), null, null, null, newUserPropertyDto("foo", "one", user)); executeRequestOnProjectSetting("foo"); assertUserPropertyExists("foo", user); @@ -195,7 +198,7 @@ public class ResetActionTest { public void remove_setting_by_deprecated_key() { logInAsSystemAdministrator(); definitions.addComponent(PropertyDefinition.builder("foo").deprecatedKey("old").build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); executeRequestOnGlobalSetting("old"); assertGlobalPropertyDoesNotExist("foo"); @@ -206,7 +209,7 @@ public class ResetActionTest { ComponentDto project = db.components().insertPublicProject(); ComponentDto branch = db.components().insertProjectBranch(project); definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build()); - propertyDb.insertProperties(null, branch.name(), null, newComponentPropertyDto(branch).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, branch.name(), null, null, newComponentPropertyDto(branch).setKey("foo").setValue("value")); userSession.logIn().addProjectPermission(ADMIN, project); ws.newRequest() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java index 40cb5265d96..f2156a5814d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SetActionTest.java @@ -138,7 +138,7 @@ public class SetActionTest { @Test public void update_existing_global_setting() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"), null, null, null); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my value"), null, null, null, null); assertGlobalSetting("my.key", "my value"); callForGlobalSetting("my.key", "my new value"); @@ -149,7 +149,7 @@ public class SetActionTest { @Test public void persist_new_project_setting() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null, null); ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); @@ -172,9 +172,11 @@ public class SetActionTest { @Test public void update_existing_project_setting() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, + null, null); ComponentDto project = db.components().insertPrivateProject(); - propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project), project.name(), null, null); + propertyDb.insertProperty(newComponentPropertyDto("my.key", "my project value", project), project.getKey(), + project.name(), null, null); assertComponentSetting("my.key", "my project value", project.uuid()); logInAsProjectAdministrator(project); @@ -256,7 +258,7 @@ public class SetActionTest { .type(PropertyType.STRING) .build())) .build()); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto("my.key", "1,2,3,4"), newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"), newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue"), @@ -305,11 +307,11 @@ public class SetActionTest { .build())) .build()); ComponentDto project = db.components().insertPrivateProject(); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto("my.key", "1"), newGlobalPropertyDto("my.key.1.firstField", "oldFirstValue"), newGlobalPropertyDto("my.key.1.secondField", "oldSecondValue")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto("my.key", "1", project), newComponentPropertyDto("my.key.1.firstField", "componentFirstValue", project), newComponentPropertyDto("my.key.1.firstField", "componentSecondValue", project)); @@ -377,8 +379,9 @@ public class SetActionTest { @Test public void user_setting_is_not_updated() { - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"), null, null, "user_login"); - propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my user value").setUserUuid("42"), null, null, + null, "user_login"); + propertyDb.insertProperty(newGlobalPropertyDto("my.key", "my global value"), null, null, null, null); callForGlobalSetting("my.key", "my new global value"); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java index 0807e2bfab6..27f8169904a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/SettingsUpdaterTest.java @@ -72,9 +72,10 @@ public class SettingsUpdaterTest { @Test public void delete_global_settings() { definitions.addComponent(PropertyDefinition.builder("foo").build()); - propertyDb.insertProperties(null, project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("value")); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("bar").setValue("two")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + newComponentPropertyDto(project).setKey("foo").setValue("value")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("bar").setValue("two")); underTest.deleteGlobalSettings(dbSession, "foo", "bar"); @@ -86,9 +87,11 @@ public class SettingsUpdaterTest { @Test public void delete_component_settings() { definitions.addComponent(PropertyDefinition.builder("foo").build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("value")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("one")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("bar").setValue("two")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("value")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + newComponentPropertyDto(project).setKey("foo").setValue("one")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), + newComponentPropertyDto(project).setKey("bar").setValue("two")); underTest.deleteComponentSettings(dbSession, project, "foo", "bar"); @@ -99,7 +102,7 @@ public class SettingsUpdaterTest { @Test public void does_not_fail_when_deleting_unknown_setting() { - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); underTest.deleteGlobalSettings(dbSession, "unknown"); @@ -109,8 +112,8 @@ public class SettingsUpdaterTest { @Test public void does_not_delete_user_settings() { UserDto user = dbClient.userDao().insert(dbSession, UserTesting.newUserDto()); - propertyDb.insertProperties(user.getLogin(), null, null, newUserPropertyDto("foo", "one", user)); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(user.getLogin(), null, null, null, newUserPropertyDto("foo", "one", user)); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); underTest.deleteGlobalSettings(dbSession, "foo"); @@ -126,7 +129,7 @@ public class SettingsUpdaterTest { PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("1,2"), newGlobalPropertyDto().setKey("foo.1.key").setValue("key1"), newGlobalPropertyDto().setKey("foo.1.size").setValue("size1"), @@ -149,7 +152,7 @@ public class SettingsUpdaterTest { PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("1,2"), newComponentPropertyDto(project).setKey("foo.1.key").setValue("key1"), newComponentPropertyDto(project).setKey("foo.1.size").setValue("size1"), @@ -172,7 +175,7 @@ public class SettingsUpdaterTest { PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build()); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("other").setValue("1,2"), newComponentPropertyDto(project).setKey("other.1.key").setValue("key1")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java index 44b54b4cb6e..7170642a5db 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/ValuesActionTest.java @@ -101,7 +101,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition .builder("foo") .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); ValuesWsResponse result = executeRequestForGlobalProperties("foo"); @@ -124,7 +124,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition.builder("global") .multiValues(true) .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("global").setValue("three,four")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("global").setValue("three,four")); ValuesWsResponse result = executeRequestForGlobalProperties("default", "global"); assertThat(result.getSettingsList()).hasSize(2); @@ -142,7 +142,7 @@ public class ValuesActionTest { public void return_multi_value_with_coma() { logIn(); definitions.addComponent(PropertyDefinition.builder("global").multiValues(true).build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive")); + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("global").setValue("three,four%2Cfive")); ValuesWsResponse result = executeRequestForGlobalProperties("global"); @@ -213,7 +213,7 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build()); propertyDb.insertProperties(null, null, null, // The property is overriding default value - newGlobalPropertyDto().setKey("property").setValue("one")); + null, newGlobalPropertyDto().setKey("property").setValue("one")); ValuesWsResponse result = executeRequestForGlobalProperties("property"); @@ -227,8 +227,8 @@ public class ValuesActionTest { definitions.addComponent( PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build()); propertyDb.insertProperties(null, null, null, - newGlobalPropertyDto().setKey("property").setValue("one")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + null, newGlobalPropertyDto().setKey("property").setValue("one")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), // The property is overriding global value newComponentPropertyDto(project).setKey("property").setValue("two")); @@ -246,8 +246,8 @@ public class ValuesActionTest { PropertyDefinition.builder("global.default").defaultValue("default").build(), PropertyDefinition.builder("project").onQualifiers(PROJECT).build())); propertyDb.insertProperties(null, null, null, - newGlobalPropertyDto().setKey("global").setValue("one")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + null, newGlobalPropertyDto().setKey("global").setValue("one")); + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("project").setValue("two")); ValuesWsResponse result = executeRequestForProjectProperties(); @@ -261,7 +261,8 @@ public class ValuesActionTest { logInAsProjectUser(); definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT).build()); // The property is not defined on project - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("property").setValue("one")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("property").setValue("one")); ValuesWsResponse result = executeRequestForProjectProperties("property"); @@ -272,7 +273,8 @@ public class ValuesActionTest { @Test public void return_values_even_if_no_property_definition() { logIn(); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("globalPropertyWithoutDefinition").setValue("value")); ValuesWsResponse result = executeRequestForGlobalProperties("globalPropertyWithoutDefinition"); @@ -285,7 +287,7 @@ public class ValuesActionTest { @Test public void return_values_of_component_even_if_no_property_definition() { logInAsProjectUser(); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("property").setValue("foo")); ValuesWsResponse response = executeRequestForComponentProperties(project, "property"); @@ -312,7 +314,8 @@ public class ValuesActionTest { .builder("foo") .defaultValue("default") .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("bar").setValue("")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("bar").setValue("")); ValuesWsResponse result = executeRequestForGlobalProperties("unknown"); @@ -324,9 +327,9 @@ public class ValuesActionTest { logInAsProjectUser(); ComponentDto module = componentDb.insertComponent(newModuleDto(project)); definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").onQualifiers(PROJECT, MODULE).build()); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("property").setValue("one")); - propertyDb.insertProperties(null, module.name(), module.qualifier(), + propertyDb.insertProperties(null, module.getKey(), module.name(), module.qualifier(), // The property is overriding global value newComponentPropertyDto(module).setKey("property").setValue("two")); @@ -345,11 +348,11 @@ public class ValuesActionTest { PropertyDefinition.builder("globalProperty").onQualifiers(PROJECT, MODULE).build(), PropertyDefinition.builder("projectProperty").onQualifiers(PROJECT, MODULE).build(), PropertyDefinition.builder("moduleProperty").onQualifiers(PROJECT, MODULE).build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("globalProperty").setValue("global")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("projectProperty").setValue("project")); - propertyDb.insertProperties(null, module.name(), module.qualifier(), + propertyDb.insertProperties(null, module.getKey(), module.name(), module.qualifier(), newComponentPropertyDto(module).setKey("moduleProperty").setValue("module")); ValuesWsResponse result = executeRequestForComponentProperties(module, "defaultProperty", "globalProperty", "projectProperty", "moduleProperty"); @@ -367,7 +370,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("defaultProperty").defaultValue("default").build(), PropertyDefinition.builder("globalProperty").build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("globalProperty").setValue("global")); ValuesWsResponse result = executeRequestForGlobalProperties("defaultProperty", "globalProperty"); @@ -384,11 +387,11 @@ public class ValuesActionTest { ComponentDto subModule = componentDb.insertComponent(newModuleDto(module)); definitions.addComponents(asList( PropertyDefinition.builder("foo").defaultValue("default").onQualifiers(PROJECT, MODULE).build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("global")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("project")); - propertyDb.insertProperties(null, module.name(), module.qualifier(), + propertyDb.insertProperties(null, module.getKey(), module.name(), module.qualifier(), newComponentPropertyDto(module).setKey("foo").setValue("module")); assertParentValue(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module"); @@ -404,11 +407,11 @@ public class ValuesActionTest { ComponentDto subModule = componentDb.insertComponent(newModuleDto(module)); definitions.addComponents(asList( PropertyDefinition.builder("foo").defaultValue("default1,default2").multiValues(true).onQualifiers(PROJECT, MODULE).build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("global1,global2")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("project1,project2")); - propertyDb.insertProperties(null, module.name(), module.qualifier(), + propertyDb.insertProperties(null, module.getKey(), module.name(), module.qualifier(), newComponentPropertyDto(module).setKey("foo").setValue("module1,module2")); assertParentValues(executeRequestForComponentProperties(subModule, "foo").getSettings(0), "module1", "module2"); @@ -455,7 +458,7 @@ public class ValuesActionTest { PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("size").name("Size").build())) .build())); - propertyDb.insertProperties(null, module.name(), module.qualifier(), + propertyDb.insertProperties(null, module.getKey(), module.name(), module.qualifier(), newComponentPropertyDto(module).setKey("simple").setValue("module"), newComponentPropertyDto(module).setKey("multi").setValue("module1,module2")); propertyDb.insertPropertySet("set", module, ImmutableMap.of("key", "keyM1", "size", "sizeM1")); @@ -469,9 +472,9 @@ public class ValuesActionTest { public void return_parent_value_when_no_definition() { logInAsProjectUser(); ComponentDto module = componentDb.insertComponent(newModuleDto(project)); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("global")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("project")); assertParentValue(executeRequestForComponentProperties(module, "foo").getSettings(0), "project"); @@ -486,7 +489,8 @@ public class ValuesActionTest { .builder("foo") .deprecatedKey("deprecated") .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("foo").setValue("one")); ValuesWsResponse result = executeRequestForGlobalProperties("deprecated"); @@ -501,7 +505,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password")); @@ -532,7 +536,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password")); @@ -550,9 +554,9 @@ public class ValuesActionTest { PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(), PropertyDefinition.builder("global.secret.secured").build(), PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("one"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password")); @@ -566,7 +570,7 @@ public class ValuesActionTest { userSession .addProjectPermission(USER, project) .addProjectPermission(SCAN_EXECUTION, project); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123")); ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured"); @@ -580,7 +584,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password")); @@ -596,9 +600,9 @@ public class ValuesActionTest { PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(), PropertyDefinition.builder("global.secret.secured").build(), PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("global.secret.secured").setValue("very secret")); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("one"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password")); @@ -610,7 +614,7 @@ public class ValuesActionTest { @Test public void return_secured_settings_even_if_not_defined_when_project_admin() { logInAsProjectAdmin(); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123")); ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured"); @@ -641,7 +645,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("foo").build(), PropertyDefinition.builder("secret.secured").build())); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one"), newGlobalPropertyDto().setKey("secret.secured").setValue("password")); @@ -656,7 +660,7 @@ public class ValuesActionTest { definitions.addComponents(asList( PropertyDefinition.builder("foo").onQualifiers(PROJECT).build(), PropertyDefinition.builder("secret.secured").onQualifiers(PROJECT).build())); - propertyDb.insertProperties(null, project.name(), project.qualifier(), + propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("foo").setValue("one"), newComponentPropertyDto(project).setKey("secret.secured").setValue("password")); @@ -669,7 +673,7 @@ public class ValuesActionTest { public void return_additional_settings_specific_for_scanner_when_no_keys() { logInAsAdmin(); definitions.addComponent(PropertyDefinition.builder("secret.secured").build()); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("sonar.core.id").setValue("ID"), newGlobalPropertyDto().setKey("sonar.core.startTime").setValue("2017-01-01")); @@ -684,7 +688,8 @@ public class ValuesActionTest { definitions.addComponent(PropertyDefinition .builder("foo") .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("fi±∞…")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("foo").setValue("fi±∞…")); ValuesWsResponse result = executeRequestForGlobalProperties("foo"); @@ -708,7 +713,8 @@ public class ValuesActionTest { .builder("foo") .deprecatedKey("deprecated") .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("foo").setValue("one")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("foo").setValue("one")); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'foo' and 'deprecated' cannot be used at the same time as they refer to the same setting"); @@ -738,7 +744,8 @@ public class ValuesActionTest { .builder("sonar.autogenerated") .multiValues(true) .build()); - propertyDb.insertProperties(null, null, null, newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3")); + propertyDb.insertProperties(null, null, null, null, + newGlobalPropertyDto().setKey("sonar.autogenerated").setValue("val1,val2,val3")); definitions.addComponent(PropertyDefinition .builder("sonar.demo") .type(PropertyType.PROPERTY_SET) @@ -801,7 +808,7 @@ public class ValuesActionTest { PropertyDefinition securedDef = PropertyDefinition.builder("my.password.secured").build(); PropertyDefinition standardDef = PropertyDefinition.builder("my.property").build(); definitions.addComponents(asList(securedDef, standardDef)); - propertyDb.insertProperties(null, null, null, + propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey(securedDef.key()).setValue("securedValue"), newGlobalPropertyDto().setKey(standardDef.key()).setValue("standardValue")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index b441ed347a2..7e2cb216de2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -156,7 +156,7 @@ public class ComponentActionTest { ComponentDto project = insertProject(); UserDto user = db.users().insertUser("obiwan"); propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()), - project.name(), project.qualifier(), user.getLogin()); + project.getKey(), project.name(), project.qualifier(), user.getLogin()); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -169,7 +169,7 @@ public class ComponentActionTest { ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz")); UserDto user = db.users().insertUser("obiwan"); propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()), - project.name(), project.qualifier(), user.getLogin()); + project.getKey(), project.name(), project.qualifier(), user.getLogin()); userSession.logIn(user).addProjectPermission(UserRole.USER, project); init(); @@ -625,7 +625,7 @@ public class ComponentActionTest { when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType()); UserDto user = db.users().insertUser("obiwan"); propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()), - project.name(), project.qualifier(), user.getLogin()); + project.getKey(), project.name(), project.qualifier(), user.getLogin()); addQualityProfiles(project, createQProfile("qp1", "Sonar Way Java", "java"), createQProfile("qp2", "Sonar Way Xoo", "xoo")); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 7367088e9e0..29350829f84 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -143,9 +143,10 @@ public class DeactivateActionTest { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); ComponentDto project = db.components().insertPrivateProject(); - db.properties().insertProperty(newUserPropertyDto(user), null, null, user.getLogin()); - db.properties().insertProperty(newUserPropertyDto(user), null, null, user.getLogin()); - db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()), project.name(), project.qualifier(), user.getLogin()); + db.properties().insertProperty(newUserPropertyDto(user), null, null, null, user.getLogin()); + db.properties().insertProperty(newUserPropertyDto(user), null,null, null, user.getLogin()); + db.properties().insertProperty(newUserPropertyDto(user).setComponentUuid(project.uuid()), project.getKey(), + project.name(), project.qualifier(), user.getLogin()); deactivate(user.getLogin()); @@ -209,11 +210,11 @@ public class DeactivateActionTest { ComponentDto project = db.components().insertPrivateProject(); ComponentDto anotherProject = db.components().insertPrivateProject(); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()) - .setComponentUuid(project.uuid()), project.name(), project.qualifier(), user.getLogin()); + .setComponentUuid(project.uuid()), project.getKey(), project.name(), project.qualifier(), user.getLogin()); db.properties().insertProperty(new PropertyDto().setKey("sonar.issues.defaultAssigneeLogin").setValue(user.getLogin()) - .setComponentUuid(anotherProject.uuid()), anotherProject.name(), anotherProject.qualifier(), user.getLogin()); + .setComponentUuid(anotherProject.uuid()), anotherProject.getKey(), anotherProject.name(), anotherProject.qualifier(), user.getLogin()); db.properties().insertProperty(new PropertyDto().setKey("other").setValue(user.getLogin()) - .setComponentUuid(anotherProject.uuid()), anotherProject.name(), anotherProject.qualifier(), user.getLogin()); + .setComponentUuid(anotherProject.uuid()), anotherProject.getKey(), anotherProject.name(), anotherProject.qualifier(), user.getLogin()); deactivate(user.getLogin()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java index d02a32acd2c..4ffb04a1558 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/webhook/ws/ListActionTest.java @@ -97,11 +97,11 @@ public class ListActionTest { @Test public void list_webhooks_and_their_latest_delivery() { - WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null); + WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null, null); webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE)); webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW)); - WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null); + WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null, null); webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE)); webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW)); @@ -125,8 +125,8 @@ public class ListActionTest { @Test public void list_webhooks_when_no_delivery() { - WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null); - WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null); + WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null, null); + WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null, null); userSession.logIn().addPermission(ADMINISTER); @@ -148,10 +148,10 @@ public class ListActionTest { public void obfuscate_credentials_in_webhook_URLs() { String url = "http://foo:barouf@toto/bop"; String expectedUrl = "http://***:******@toto/bop"; - WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null); + WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa", t -> t.setUrl(url)), null, null); webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE)); webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW)); - webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null); + webhookDbTester.insert(newGlobalWebhook("bbb", t -> t.setUrl(url)), null, null); userSession.logIn().addPermission(ADMINISTER); |