소스 검색

SONAR-9304 rename table qprofiles to org_qprofiles

tags/6.5-M1
Simon Brandhof 7 년 전
부모
커밋
3e26c9b9b4
100개의 변경된 파일1295개의 추가작업 그리고 1235개의 파일을 삭제
  1. 3
    3
      server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java
  2. 3
    4
      server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
  3. 0
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java
  4. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java
  5. 1
    1
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java
  6. 4
    6
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java
  7. 2
    2
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java
  8. 5
    5
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java
  9. 16
    16
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java
  10. 62
    58
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java
  11. 33
    22
      server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java
  12. 2
    1
      server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml
  13. 20
    16
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml
  14. 6
    6
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml
  15. 250
    179
      server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml
  16. 2
    2
      server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
  17. 3
    3
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java
  18. 24
    14
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java
  19. 5
    13
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java
  20. 350
    198
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
  21. 39
    49
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java
  22. 13
    15
      server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java
  23. 0
    16
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml
  24. 0
    71
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml
  25. 0
    43
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml
  26. 0
    37
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml
  27. 0
    36
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml
  28. 0
    37
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml
  29. 0
    28
      server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml
  30. 17
    10
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java
  31. 2
    1
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
  32. 41
    0
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java
  33. 13
    9
      server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java
  34. 6
    5
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java
  35. 1
    1
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java
  36. 43
    0
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java
  37. 11
    11
      server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java
  38. 0
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql
  39. 15
    0
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql
  40. 3
    2
      server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql
  41. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
  42. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java
  43. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java
  44. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java
  45. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java
  46. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java
  47. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java
  48. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
  49. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java
  50. 17
    17
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
  51. 8
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java
  52. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java
  53. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java
  54. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java
  55. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java
  56. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java
  57. 16
    16
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java
  58. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java
  59. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java
  60. 1
    11
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java
  61. 11
    12
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java
  62. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java
  63. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java
  64. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java
  65. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java
  66. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java
  67. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
  68. 1
    1
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java
  69. 4
    4
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java
  70. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
  71. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java
  72. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java
  73. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java
  74. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java
  75. 6
    6
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java
  76. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java
  77. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java
  78. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java
  79. 8
    8
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java
  80. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java
  81. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java
  82. 2
    2
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java
  83. 10
    10
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
  84. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java
  85. 19
    19
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java
  86. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java
  87. 0
    3
      server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java
  88. 7
    7
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java
  89. 3
    3
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java
  90. 5
    5
      server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java
  91. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java
  92. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java
  93. 16
    16
      server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java
  94. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
  95. 9
    9
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java
  96. 3
    3
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java
  97. 4
    4
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java
  98. 2
    2
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java
  99. 6
    6
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java
  100. 0
    0
      server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java

+ 3
- 3
server/sonar-db-core/src/main/java/org/sonar/db/version/SqTables.java 파일 보기

@@ -68,19 +68,19 @@ public final class SqTables {
"notifications",
"organizations",
"organization_members",
"org_qprofiles",
"permission_templates",
"perm_templates_users",
"perm_templates_groups",
"perm_tpl_characteristics",
"quality_gates",
"quality_gate_conditions",
"projects",
"project_links",
"project_measures",
"project_qprofiles",
"properties",
"qprofile_changes",
"qprofiles",
"quality_gates",
"quality_gate_conditions",
"rules",
"rules_metadata",
"rules_parameters",

+ 3
- 4
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl 파일 보기

@@ -47,9 +47,7 @@ CREATE TABLE "RULES_PROFILES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"KEE" VARCHAR(255) NOT NULL,
"PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
@@ -60,7 +58,7 @@ CREATE TABLE "RULES_PROFILES" (
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");


CREATE TABLE "QPROFILES" (
CREATE TABLE "ORG_QPROFILES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
@@ -68,7 +66,8 @@ CREATE TABLE "QPROFILES" (
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID");
CREATE INDEX "ORG_QPROFILES_ORG_UUID" ON "ORG_QPROFILES" ("ORGANIZATION_UUID");
CREATE INDEX "ORG_QPROFILES_RP_UUID" ON "ORG_QPROFILES" ("RULES_PROFILE_UUID");


CREATE TABLE "DEFAULT_QPROFILES" (

+ 0
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/MyBatis.java 파일 보기

@@ -97,7 +97,6 @@ import org.sonar.db.qualityprofile.ActiveRuleMapper;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileMapper;
import org.sonar.db.qualityprofile.QProfileChangeMapper;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QualityProfileMapper;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleMapper;
@@ -166,7 +165,6 @@ public class MyBatis implements Startable {
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class);
confBuilder.loadAlias("QualityGate", QualityGateDto.class);
confBuilder.loadAlias("RulesProfile", RulesProfileDto.class);
confBuilder.loadAlias("RequirementMigration", RequirementMigrationDto.class);
confBuilder.loadAlias("Resource", ResourceDto.class);
confBuilder.loadAlias("RuleParam", RuleParamDto.class);

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/ActiveRuleDto.java 파일 보기

@@ -142,7 +142,7 @@ public class ActiveRuleDto {
return this;
}

public static ActiveRuleDto createFor(RulesProfileDto profileDto, RuleDefinitionDto ruleDto) {
public static ActiveRuleDto createFor(QProfileDto profileDto, RuleDefinitionDto ruleDto) {
requireNonNull(profileDto.getId(), "Profile is not persisted");
requireNonNull(ruleDto.getId(), "Rule is not persisted");
ActiveRuleDto dto = new ActiveRuleDto();

+ 1
- 1
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/DefaultQProfileDto.java 파일 보기

@@ -52,7 +52,7 @@ public class DefaultQProfileDto {
return this;
}

public static DefaultQProfileDto from(RulesProfileDto profile) {
public static DefaultQProfileDto from(QProfileDto profile) {
return new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())

+ 4
- 6
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeDao.java 파일 보기

@@ -40,9 +40,7 @@ public class QProfileChangeDao implements Dao {
}

public void insert(DbSession dbSession, QProfileChangeDto dto) {
checkState(dto.getKey() == null, "Key of QProfileChangeDto must be set by DAO only. Got %s.", dto.getKey());
checkState(dto.getCreatedAt() == 0L, "Date of QProfileChangeDto must be set by DAO only. Got %s.", dto.getCreatedAt());

dto.setKey(uuidFactory.create());
dto.setCreatedAt(system2.now());
mapper(dbSession).insert(dto);
@@ -52,13 +50,13 @@ public class QProfileChangeDao implements Dao {
return mapper(dbSession).selectByQuery(query);
}

public int countForProfileKey(DbSession dbSession, String profileKey) {
return mapper(dbSession).countForProfileKey(profileKey);
public int countForProfileUuid(DbSession dbSession, String profileUuid) {
return mapper(dbSession).countForProfileUuid(profileUuid);
}

public void deleteByProfileKeys(DbSession dbSession, Collection<String> profileKeys) {
public void deleteByProfileKeys(DbSession dbSession, Collection<String> profileUuids) {
QProfileChangeMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteByProfileKeys);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteByProfileUuids);
}

private static QProfileChangeMapper mapper(DbSession dbSession) {

+ 2
- 2
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeMapper.java 파일 보기

@@ -29,7 +29,7 @@ public interface QProfileChangeMapper {

List<QProfileChangeDto> selectByQuery(@Param("query") QProfileChangeQuery query);

int countForProfileKey(@Param("profileKey") String profileKey);
int countForProfileUuid(@Param("profileUuid") String profileUuid);

void deleteByProfileKeys(@Param("profileKeys") Collection<String> profileKeys);
void deleteByProfileUuids(@Param("profileUuids") Collection<String> profileUuids);
}

+ 5
- 5
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileChangeQuery.java 파일 보기

@@ -28,18 +28,18 @@ import static java.util.Objects.requireNonNull;

public class QProfileChangeQuery {

private final String profileKey;
private final String profileUuid;
private Long fromIncluded;
private Long toExcluded;
private int offset = 0;
private int limit = 100;

public QProfileChangeQuery(String profileKey) {
this.profileKey = requireNonNull(profileKey);
public QProfileChangeQuery(String profileUuid) {
this.profileUuid = requireNonNull(profileUuid);
}

public String getProfileKey() {
return profileKey;
public String getProfileUuid() {
return profileUuid;
}

@CheckForNull

server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/RulesProfileDto.java → server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileDto.java 파일 보기

@@ -26,9 +26,9 @@ import org.sonar.core.util.UtcDateUtils;
import org.sonar.db.organization.OrganizationDto;

/**
* Represents the table "rules_profiles"
* Represents the join of "org_qprofiles" and "rules_profiles"
*/
public class RulesProfileDto {
public class QProfileDto {

private Integer id;
/**
@@ -50,12 +50,12 @@ public class RulesProfileDto {
return organizationUuid;
}

public RulesProfileDto setOrganizationUuid(String organizationUuid) {
public QProfileDto setOrganizationUuid(String organizationUuid) {
this.organizationUuid = organizationUuid;
return this;
}

public RulesProfileDto setKey(String s) {
public QProfileDto setKey(String s) {
return setKee(s);
}

@@ -63,7 +63,7 @@ public class RulesProfileDto {
return kee;
}

public RulesProfileDto setKee(String s) {
public QProfileDto setKee(String s) {
this.kee = s;
return this;
}
@@ -72,7 +72,7 @@ public class RulesProfileDto {
return id;
}

public RulesProfileDto setId(Integer id) {
public QProfileDto setId(Integer id) {
this.id = id;
return this;
}
@@ -81,7 +81,7 @@ public class RulesProfileDto {
return name;
}

public RulesProfileDto setName(String name) {
public QProfileDto setName(String name) {
this.name = name;
return this;
}
@@ -90,7 +90,7 @@ public class RulesProfileDto {
return language;
}

public RulesProfileDto setLanguage(String language) {
public QProfileDto setLanguage(String language) {
this.language = language;
return this;
}
@@ -100,7 +100,7 @@ public class RulesProfileDto {
return parentKee;
}

public RulesProfileDto setParentKee(@Nullable String s) {
public QProfileDto setParentKee(@Nullable String s) {
this.parentKee = s;
return this;
}
@@ -109,12 +109,12 @@ public class RulesProfileDto {
return rulesUpdatedAt;
}

public RulesProfileDto setRulesUpdatedAt(String s) {
public QProfileDto setRulesUpdatedAt(String s) {
this.rulesUpdatedAt = s;
return this;
}

public RulesProfileDto setRulesUpdatedAtAsDate(Date d) {
public QProfileDto setRulesUpdatedAtAsDate(Date d) {
this.rulesUpdatedAt = UtcDateUtils.formatDateTime(d);
return this;
}
@@ -124,7 +124,7 @@ public class RulesProfileDto {
return lastUsed;
}

public RulesProfileDto setLastUsed(@Nullable Long lastUsed) {
public QProfileDto setLastUsed(@Nullable Long lastUsed) {
this.lastUsed = lastUsed;
return this;
}
@@ -134,7 +134,7 @@ public class RulesProfileDto {
return userUpdatedAt;
}

public RulesProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
public QProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
this.userUpdatedAt = userUpdatedAt;
return this;
}
@@ -143,12 +143,12 @@ public class RulesProfileDto {
return isBuiltIn;
}

public RulesProfileDto setIsBuiltIn(boolean b) {
public QProfileDto setIsBuiltIn(boolean b) {
this.isBuiltIn = b;
return this;
}

public static RulesProfileDto createFor(String key) {
return new RulesProfileDto().setKee(key);
public static QProfileDto createFor(String key) {
return new QProfileDto().setKee(key);
}
}

+ 62
- 58
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileDao.java 파일 보기

@@ -20,7 +20,7 @@
package org.sonar.db.qualityprofile;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -49,84 +49,87 @@ public class QualityProfileDao implements Dao {
}

@CheckForNull
public RulesProfileDto selectByKey(DbSession session, String key) {
return mapper(session).selectByKey(key);
public QProfileDto selectByUuid(DbSession session, String uuid) {
return mapper(session).selectByUuid(uuid);
}

public RulesProfileDto selectOrFailByKey(DbSession session, String key) {
RulesProfileDto dto = selectByKey(session, key);
public QProfileDto selectOrFailByUuid(DbSession session, String uuid) {
QProfileDto dto = selectByUuid(session, uuid);
if (dto == null) {
throw new RowNotFoundException("Quality profile not found: " + key);
throw new RowNotFoundException("Quality profile not found: " + uuid);
}
return dto;
}

public List<RulesProfileDto> selectByKeys(DbSession session, List<String> keys) {
return executeLargeInputs(keys, mapper(session)::selectByKeys);
public List<QProfileDto> selectByUuids(DbSession session, List<String> uuids) {
return executeLargeInputs(uuids, mapper(session)::selectByUuids);
}

public List<RulesProfileDto> selectAll(DbSession session, OrganizationDto organization) {
public List<QProfileDto> selectAll(DbSession session, OrganizationDto organization) {
return mapper(session).selectAll(organization.getUuid());
}

public void insert(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
public void insert(DbSession session, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
doInsert(mapper, profile);
for (RulesProfileDto other : otherProfiles) {
for (QProfileDto other : otherProfiles) {
doInsert(mapper, other);
}
}

private void doInsert(QualityProfileMapper mapper, RulesProfileDto profile) {
private void doInsert(QualityProfileMapper mapper, QProfileDto profile) {
Preconditions.checkArgument(profile.getId() == null, "Quality profile is already persisted (got id %d)", profile.getId());
mapper.insert(profile, new Date(system.now()));
long now = system.now();
mapper.insertRulesProfile(profile, new Date(now));
mapper.insertOrgQProfile(profile, now);
}

public void update(DbSession session, RulesProfileDto profile, RulesProfileDto... otherProfiles) {
public void update(DbSession session, QProfileDto profile, QProfileDto... otherProfiles) {
QualityProfileMapper mapper = mapper(session);
doUpdate(mapper, profile);
for (RulesProfileDto otherProfile : otherProfiles) {
doUpdate(mapper, otherProfile);
long now = system.now();
doUpdate(mapper, profile, now);
for (QProfileDto otherProfile : otherProfiles) {
doUpdate(mapper, otherProfile, now);
}
}

private void doUpdate(QualityProfileMapper mapper, RulesProfileDto profile) {
Preconditions.checkArgument(profile.getId() != null, "Quality profile is not persisted");
mapper.update(profile, new Date(system.now()));
private void doUpdate(QualityProfileMapper mapper, QProfileDto profile, long now) {
mapper.updateRulesProfile(profile, new Date(now));
mapper.updateOrgQProfile(profile, now);
}

public List<RulesProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languageKeys) {
return mapper(session).selectDefaultProfiles(organization.getUuid(), languageKeys);
public List<QProfileDto> selectDefaultProfiles(DbSession session, OrganizationDto organization, Collection<String> languages) {
return mapper(session).selectDefaultProfiles(organization.getUuid(), languages);
}

@CheckForNull
public RulesProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
public QProfileDto selectDefaultProfile(DbSession session, OrganizationDto organization, String language) {
return mapper(session).selectDefaultProfile(organization.getUuid(), language);
}

@CheckForNull
public RulesProfileDto selectAssociatedToProjectAndLanguage(DbSession session, ComponentDto project, String language) {
public QProfileDto selectAssociatedToProjectAndLanguage(DbSession session, ComponentDto project, String language) {
return mapper(session).selectAssociatedToProjectUuidAndLanguage(project.getOrganizationUuid(), project.projectUuid(), language);
}

public List<RulesProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession session, ComponentDto project, Collection<String> languages) {
public List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(DbSession session, ComponentDto project, Collection<String> languages) {
return mapper(session).selectAssociatedToProjectUuidAndLanguages(project.getOrganizationUuid(), project.uuid(), languages);
}

public List<RulesProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
public List<QProfileDto> selectByLanguage(DbSession dbSession, OrganizationDto organization, String language) {
return mapper(dbSession).selectByLanguage(organization.getUuid(), language);
}

public List<RulesProfileDto> selectChildren(DbSession session, String key) {
return mapper(session).selectChildren(key);
public List<QProfileDto> selectChildren(DbSession session, String uuid) {
return mapper(session).selectChildren(uuid);
}

/**
* All descendants, in the top-down order.
*/
public List<RulesProfileDto> selectDescendants(DbSession session, String key) {
List<RulesProfileDto> descendants = Lists.newArrayList();
for (RulesProfileDto child : selectChildren(session, key)) {
public List<QProfileDto> selectDescendants(DbSession session, String uuid) {
List<QProfileDto> descendants = new ArrayList<>();
for (QProfileDto child : selectChildren(session, uuid)) {
descendants.add(child);
descendants.addAll(selectDescendants(session, child.getKee()));
}
@@ -134,63 +137,69 @@ public class QualityProfileDao implements Dao {
}

@CheckForNull
public RulesProfileDto selectByNameAndLanguage(OrganizationDto organization, String name, String language, DbSession session) {
public QProfileDto selectByNameAndLanguage(DbSession session, OrganizationDto organization, String name, String language) {
return mapper(session).selectByNameAndLanguage(organization.getUuid(), name, language);
}

public List<RulesProfileDto> selectByNameAndLanguages(OrganizationDto organization, String name, Collection<String> languageKeys, DbSession session) {
return mapper(session).selectByNameAndLanguages(organization.getUuid(), name, languageKeys);
public List<QProfileDto> selectByNameAndLanguages(DbSession session, OrganizationDto organization, String name, Collection<String> languages) {
return mapper(session).selectByNameAndLanguages(organization.getUuid(), name, languages);
}

public Map<String, Long> countProjectsByProfileKey(DbSession dbSession, OrganizationDto organization) {
return KeyLongValue.toMap(mapper(dbSession).countProjectsByProfileKey(organization.getUuid()));
public Map<String, Long> countProjectsByProfileUuid(DbSession dbSession, OrganizationDto organization) {
return KeyLongValue.toMap(mapper(dbSession).countProjectsByProfileUuid(organization.getUuid()));
}

public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, RulesProfileDto profile) {
public void insertProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
mapper(dbSession).insertProjectProfileAssociation(project.uuid(), profile.getKee());
}

public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, RulesProfileDto profile) {
public void deleteProjectProfileAssociation(DbSession dbSession, ComponentDto project, QProfileDto profile) {
mapper(dbSession).deleteProjectProfileAssociation(project.uuid(), profile.getKee());
}

public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileKey, String oldProfileKey) {
mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileKey, oldProfileKey);
public void updateProjectProfileAssociation(DbSession dbSession, ComponentDto project, String newProfileUuid, String oldProfileUuid) {
mapper(dbSession).updateProjectProfileAssociation(project.uuid(), newProfileUuid, oldProfileUuid);
}

public void deleteProjectAssociationsByProfileKeys(DbSession dbSession, Collection<String> profileKeys) {
public void deleteProjectAssociationsByProfileUuids(DbSession dbSession, Collection<String> profileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteProjectAssociationByProfileKeys);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteProjectAssociationByProfileUuids);
}

public List<ProjectQprofileAssociationDto> selectSelectedProjects(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
public List<ProjectQprofileAssociationDto> selectSelectedProjects(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(session).selectSelectedProjects(organization.getUuid(), profileKey, nameQuery);
return mapper(session).selectSelectedProjects(organization.getUuid(), profile.getKee(), nameQuery);
}

public List<ProjectQprofileAssociationDto> selectDeselectedProjects(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
public List<ProjectQprofileAssociationDto> selectDeselectedProjects(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(session).selectDeselectedProjects(organization.getUuid(), profileKey, nameQuery);
return mapper(session).selectDeselectedProjects(organization.getUuid(), profile.getKee(), nameQuery);
}

public List<ProjectQprofileAssociationDto> selectProjectAssociations(OrganizationDto organization, String profileKey, @Nullable String query, DbSession session) {
public List<ProjectQprofileAssociationDto> selectProjectAssociations(DbSession session, OrganizationDto organization, QProfileDto profile, @Nullable String query) {
String nameQuery = sqlQueryString(query);
return mapper(session).selectProjectAssociations(organization.getUuid(), profileKey, nameQuery);
return mapper(session).selectProjectAssociations(organization.getUuid(), profile.getKee(), nameQuery);
}

public Collection<String> selectOutdatedProfiles(DbSession dbSession, String language, String name) {
return mapper(dbSession).selectOutdatedProfiles(language, name);
public Collection<String> selectUuidsOfCustomRulesProfiles(DbSession dbSession, String language, String name) {
return mapper(dbSession).selectUuidsOfCustomQProfiles(language, name);
}

public void renameAndCommit(DbSession dbSession, Collection<String> keys, String newName) {
public void renameRulesProfilesAndCommit(DbSession dbSession, Collection<String> rulesProfileUuids, String newName) {
QualityProfileMapper mapper = mapper(dbSession);
Date now = new Date(system.now());
executeLargeUpdates(keys, partition -> {
mapper.rename(newName, now, partition);
executeLargeUpdates(rulesProfileUuids, partition -> {
mapper.renameRulesProfiles(newName, now, partition);
dbSession.commit();
});
}

public void deleteByUuids(DbSession dbSession, Collection<String> profileUuids) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteOrgQProfilesByUuids);
DatabaseUtils.executeLargeUpdates(profileUuids, mapper::deleteRulesProfilesByUuids);
}

private static String sqlQueryString(@Nullable String query) {
if (query == null) {
return "%";
@@ -201,9 +210,4 @@ public class QualityProfileDao implements Dao {
private static QualityProfileMapper mapper(DbSession session) {
return session.getMapper(QualityProfileMapper.class);
}

public void deleteByKeys(DbSession dbSession, Collection<String> profileKeys) {
QualityProfileMapper mapper = mapper(dbSession);
DatabaseUtils.executeLargeUpdates(profileKeys, mapper::deleteByKeys);
}
}

+ 33
- 22
server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QualityProfileMapper.java 파일 보기

@@ -28,51 +28,62 @@ import org.sonar.db.KeyLongValue;

public interface QualityProfileMapper {

void insert(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
void insertOrgQProfile(@Param("dto") QProfileDto dto, @Param("now") long now);

void update(@Param("dto") RulesProfileDto dto, @Param("now") Date now);
void insertRulesProfile(@Param("dto") QProfileDto dto, @Param("now") Date now);

void deleteByKeys(@Param("profileKeys") Collection<String> profileKeys);
void updateRulesProfile(@Param("dto") QProfileDto dto, @Param("now") Date now);

List<RulesProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);
void updateOrgQProfile(@Param("dto") QProfileDto dto, @Param("now") long now);

void deleteRulesProfilesByUuids(@Param("uuids") Collection<String> uuids);

void deleteOrgQProfilesByUuids(@Param("uuids") Collection<String> uuids);

List<QProfileDto> selectAll(@Param("organizationUuid") String organizationUuid);

@CheckForNull
RulesProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
QProfileDto selectDefaultProfile(@Param("organizationUuid") String organizationUuid, @Param("language") String language);

List<RulesProfileDto> selectDefaultProfiles(
List<QProfileDto> selectDefaultProfiles(
@Param("organizationUuid") String organizationUuid,
@Param("languages") Collection<String> languages);

@CheckForNull
RulesProfileDto selectByNameAndLanguage(@Param("organizationUuid") String organizationUuid, @Param("name") String name, @Param("language") String language);
QProfileDto selectByNameAndLanguage(
@Param("organizationUuid") String organizationUuid,
@Param("name") String name,
@Param("language") String language);

List<RulesProfileDto> selectByNameAndLanguages(
List<QProfileDto> selectByNameAndLanguages(
@Param("organizationUuid") String organizationUuid,
@Param("name") String name,
@Param("languages") Collection<String> languages);

@CheckForNull
RulesProfileDto selectByKey(String key);
QProfileDto selectByUuid(String uuid);

List<RulesProfileDto> selectByLanguage(@Param("organizationUuid") String organizationUuid, @Param("language") String language);
List<QProfileDto> selectByUuids(@Param("uuids") Collection<String> uuids);

List<RulesProfileDto> selectByKeys(@Param("keys") List<String> keys);
List<QProfileDto> selectByLanguage(
@Param("organizationUuid") String organizationUuid,
@Param("language") String language);

// INHERITANCE

List<RulesProfileDto> selectChildren(String key);
List<QProfileDto> selectChildren(String uuid);

// PROJECTS

List<KeyLongValue> countProjectsByProfileKey(@Param("organizationUuid") String organizationUuid);
List<KeyLongValue> countProjectsByProfileUuid(@Param("organizationUuid") String organizationUuid);

@CheckForNull
RulesProfileDto selectAssociatedToProjectUuidAndLanguage(
QProfileDto selectAssociatedToProjectUuidAndLanguage(
@Param("organizationUuid") String organizationUuid,
@Param("projectUuid") String projectUuid,
@Param("language") String language);

List<RulesProfileDto> selectAssociatedToProjectUuidAndLanguages(
List<QProfileDto> selectAssociatedToProjectUuidAndLanguages(
@Param("organizationUuid") String organizationUuid,
@Param("projectUuid") String projectUuid,
@Param("languages") Collection<String> languages);
@@ -86,26 +97,26 @@ public interface QualityProfileMapper {
@Param("profileUuid") String profileUuid,
@Param("oldProfileUuid") String oldProfileUuid);

void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileKey") String profileKey);
void deleteProjectProfileAssociation(@Param("projectUuid") String projectUuid, @Param("profileUuid") String profileUuid);

void deleteProjectAssociationByProfileKeys(@Param("profileKeys") Collection<String> profileKeys);
void deleteProjectAssociationByProfileUuids(@Param("profileUuids") Collection<String> profileUuids);

List<ProjectQprofileAssociationDto> selectSelectedProjects(
@Param("organizationUuid") String organizationUuid,
@Param("profileKey") String profileKey,
@Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);

List<ProjectQprofileAssociationDto> selectDeselectedProjects(
@Param("organizationUuid") String organizationUuid,
@Param("profileKey") String profileKey,
@Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);

List<ProjectQprofileAssociationDto> selectProjectAssociations(
@Param("organizationUuid") String organizationUuid,
@Param("profileKey") String profileKey,
@Param("profileUuid") String profileUuid,
@Param("nameQuery") String nameQuery);

List<String> selectOutdatedProfiles(@Param("language") String language, @Param("name") String name);
List<String> selectUuidsOfCustomQProfiles(@Param("language") String language, @Param("name") String name);

void rename(@Param("newName") String newName, @Param("updatedAt") Date updatedAt, @Param("profileKeys") Collection<String> profileKeys);
void renameRulesProfiles(@Param("newName") String newName, @Param("updatedAt") Date updatedAt, @Param("uuids") Collection<String> uuids);
}

+ 2
- 1
server/sonar-db-dao/src/main/resources/org/sonar/db/organization/OrganizationMapper.xml 파일 보기

@@ -135,7 +135,8 @@
from organizations org
where not exists (
select 1 from rules_profiles p
where p.organization_uuid = org.uuid
inner join org_qprofiles oqp on oqp.rules_profile_uuid = p.kee
where oqp.organization_uuid = org.uuid
and p.language = #{profileLanguage, jdbcType=VARCHAR}
and p.name = #{profileName, jdbcType=VARCHAR}
)

+ 20
- 16
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/ActiveRuleMapper.xml 파일 보기

@@ -17,8 +17,9 @@
</sql>

<sql id="activeRuleKeyJoin">
INNER JOIN rules_profiles qp ON qp.id=a.profile_id
INNER JOIN rules r ON r.id = a.rule_id
inner join rules_profiles qp on qp.id=a.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = qp.kee
inner join rules r on r.id = a.rule_id
</sql>

<insert id="insert" parameterType="ActiveRule" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
@@ -88,7 +89,7 @@
FROM active_rules a
<include refid="activeRuleKeyJoin"/>
WHERE a.rule_id=#{ruleId, jdbcType=BIGINT}
AND qp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
AND oqp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectByRuleIdOfAllOrganizations" parameterType="Integer" resultType="ActiveRule">
@@ -109,7 +110,7 @@
<foreach collection="ruleIds" item="ruleId" separator="," open="(" close=")">
#{ruleId}
</foreach>
AND qp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
AND oqp.organization_uuid=#{organizationUuid, jdbcType=VARCHAR}
</select>

<!-- Parameters -->
@@ -191,34 +192,37 @@
</select>

<select id="countActiveRulesByProfileKey" resultType="KeyLongValue" parameterType="map">
select p.kee as "key", count(ar.id) as "value"
select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
inner join rules_profiles p on p.id = ar.profile_id
inner join rules_profiles rp on rp.id = ar.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and r.status != 'REMOVED'
group by p.kee
group by rp.kee
</select>

<select id="countActiveRulesForRuleStatusByProfileKey" resultType="KeyLongValue" parameterType="map">
select p.kee as "key", count(ar.id) as "value"
select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
inner join rules_profiles p on p.id = ar.profile_id
inner join rules_profiles rp on rp.id = ar.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and r.status = #{ruleStatus, jdbcType=VARCHAR}
group by p.kee
group by rp.kee
</select>

<select id="countActiveRulesForInheritanceByProfileKey" resultType="KeyLongValue" parameterType="map">
select p.kee as "key", count(ar.id) as "value"
select rp.kee as "key", count(ar.id) as "value"
from active_rules ar
inner join rules_profiles p on p.id = ar.profile_id
inner join rules_profiles rp on rp.id = ar.profile_id
inner join org_qprofiles oqp on oqp.rules_profile_uuid = rp.kee
inner join rules r on r.id = ar.rule_id
where p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
where oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and ar.inheritance = #{inheritance, jdbcType=VARCHAR}
and r.status != 'REMOVED'
group by p.kee
group by rp.kee
</select>
</mapper>


+ 6
- 6
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileChangeMapper.xml 파일 보기

@@ -22,9 +22,9 @@
)
</insert>

<select id="countForProfileKey" resultType="int">
<select id="countForProfileUuid" resultType="int">
select count(kee) from qprofile_changes
where qprofile_key = #{profileKey}
where qprofile_key = #{profileUuid, jdbcType=VARCHAR}
</select>

<select id="selectByQuery" resultType="org.sonar.db.qualityprofile.QProfileChangeDto">
@@ -61,7 +61,7 @@
<sql id="sqlSelectByQuery">
select <include refid="sqlColumns" />
from qprofile_changes
where qprofile_key = #{query.profileKey}
where qprofile_key = #{query.profileUuid, jdbcType=VARCHAR}
<if test="query.fromIncluded != null">
and created_at &gt;= #{query.fromIncluded}
</if>
@@ -71,11 +71,11 @@
order by created_at desc
</sql>

<delete id="deleteByProfileKeys" parameterType="String">
<delete id="deleteByProfileUuids" parameterType="String">
delete from qprofile_changes
where qprofile_key in
<foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">
#{profileKey, jdbcType=VARCHAR}
<foreach collection="profileUuids" open="(" close=")" item="profileUuid" separator=",">
#{profileUuid, jdbcType=VARCHAR}
</foreach>
</delete>
</mapper>

+ 250
- 179
server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QualityProfileMapper.xml 파일 보기

@@ -3,201 +3,226 @@

<mapper namespace="org.sonar.db.qualityprofile.QualityProfileMapper">

<sql id="profilesColumns">
p.id as id,
p.organization_uuid as organizationUuid,
p.kee as kee,
p.name as name,
p.language as language,
p.parent_kee as parentKee,
p.rules_updated_at as rulesUpdatedAt,
p.last_used as lastUsed,
p.user_updated_at as userUpdatedAt,
p.is_built_in as isBuiltIn
<sql id="qProfileColumns">
oqp.uuid as kee,
oqp.organization_uuid as organizationUuid,
oqp.parent_uuid as parentKee,
rp.id as id,
rp.name as name,
rp.language as language,
rp.rules_updated_at as rulesUpdatedAt,
rp.last_used as lastUsed,
rp.user_updated_at as userUpdatedAt,
rp.is_built_in as isBuiltIn
</sql>

<insert id="insert" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.id">
INSERT INTO rules_profiles (organization_uuid, kee, parent_kee, name, language, created_at, updated_at, rules_updated_at, last_used, user_updated_at, is_built_in)
VALUES (
#{dto.organizationUuid, jdbcType=VARCHAR},
#{dto.kee, jdbcType=VARCHAR},
#{dto.parentKee, jdbcType=VARCHAR},
#{dto.name, jdbcType=VARCHAR},
#{dto.language, jdbcType=VARCHAR},
#{now, jdbcType=TIMESTAMP},
#{now, jdbcType=TIMESTAMP},
#{dto.rulesUpdatedAt, jdbcType=VARCHAR},
#{dto.lastUsed, jdbcType=BIGINT},
#{dto.userUpdatedAt, jdbcType=BIGINT},
#{dto.isBuiltIn, jdbcType=BOOLEAN}
<insert id="insertRulesProfile" parameterType="map" keyColumn="id" useGeneratedKeys="true" keyProperty="dto.id">
insert into rules_profiles (
kee,
name,
language,
created_at,
updated_at,
rules_updated_at,
last_used,
user_updated_at,
is_built_in
) values (
#{dto.kee, jdbcType=VARCHAR},
#{dto.name, jdbcType=VARCHAR},
#{dto.language, jdbcType=VARCHAR},
#{now, jdbcType=TIMESTAMP},
#{now, jdbcType=TIMESTAMP},
#{dto.rulesUpdatedAt, jdbcType=VARCHAR},
#{dto.lastUsed, jdbcType=BIGINT},
#{dto.userUpdatedAt, jdbcType=BIGINT},
#{dto.isBuiltIn, jdbcType=BOOLEAN}
)
</insert>

<insert id="insertOrgQProfile" parameterType="map" useGeneratedKeys="false">
insert into org_qprofiles (
uuid,
organization_uuid,
rules_profile_uuid,
parent_uuid,
created_at,
updated_at
) values (
#{dto.kee, jdbcType=VARCHAR},
#{dto.organizationUuid, jdbcType=VARCHAR},
#{dto.kee, jdbcType=VARCHAR},
#{dto.parentKee, jdbcType=VARCHAR},
#{now, jdbcType=BIGINT},
#{now, jdbcType=BIGINT}
)
</insert>

<update id="update" parameterType="map">
UPDATE rules_profiles SET
name=#{dto.name, jdbcType=VARCHAR},
language=#{dto.language, jdbcType=VARCHAR},
parent_kee=#{dto.parentKee, jdbcType=VARCHAR},
updated_at=#{now, jdbcType=TIMESTAMP},
rules_updated_at=#{dto.rulesUpdatedAt, jdbcType=VARCHAR},
last_used=#{dto.lastUsed, jdbcType=BIGINT},
user_updated_at=#{dto.userUpdatedAt, jdbcType=BIGINT},
is_built_in=#{dto.isBuiltIn, jdbcType=BOOLEAN}
WHERE id=#{dto.id}
<update id="updateRulesProfile" parameterType="map">
update rules_profiles
set
name = #{dto.name, jdbcType=VARCHAR},
language = #{dto.language, jdbcType=VARCHAR},
updated_at = #{now, jdbcType=TIMESTAMP},
rules_updated_at = #{dto.rulesUpdatedAt, jdbcType=VARCHAR},
last_used = #{dto.lastUsed, jdbcType=BIGINT},
user_updated_at = #{dto.userUpdatedAt, jdbcType=BIGINT},
is_built_in = #{dto.isBuiltIn, jdbcType=BOOLEAN}
where
kee = #{dto.kee, jdbcType=VARCHAR}
</update>

<update id="updateOrgQProfile" parameterType="map">
update org_qprofiles
set
parent_uuid = #{dto.parentKee, jdbcType=VARCHAR},
updated_at = #{now, jdbcType=BIGINT}
where
uuid = #{dto.kee, jdbcType=VARCHAR}
</update>

<update id="deleteByKeys" parameterType="String">
<delete id="deleteRulesProfilesByUuids" parameterType="String">
delete from rules_profiles
where kee in
<foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach>
</update>
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</delete>

<select id="selectAll" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
ORDER BY p.name, p.language
</select>

<select id="selectByNameAndLanguage" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.name=#{name, jdbcType=VARCHAR}
AND p.language=#{language, jdbcType=VARCHAR}
<if test="organizationUuid != null">
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</if>
</select>

<select id="selectByNameAndLanguages" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.name=#{name, jdbcType=VARCHAR}
AND p.language IN <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectByKey" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.kee=#{id}
</select>

<select id="selectByKeys" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.kee in
<foreach collection="keys" open="(" close=")" item="key" separator=",">
#{key}
</foreach>
<delete id="deleteOrgQProfilesByUuids" parameterType="String">
delete from org_qprofiles
where uuid in
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</delete>

<select id="selectAll" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
oqp.organization_uuid = #{organizationUuid,jdbcType=VARCHAR}
order by rp.name, rp.language
</select>

<select id="selectByLanguage" parameterType="String" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.language=#{language}
AND p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY p.name
<select id="selectDefaultProfile" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
where
dp.language = #{language, jdbcType=VARCHAR}
and dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and rp.language = dp.language
and oqp.organization_uuid = dp.organization_uuid
</select>

<select id="selectChildren" parameterType="string" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
WHERE p.parent_kee=#{id}
ORDER BY p.name
<select id="selectDefaultProfiles" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join default_qprofiles dp on dp.qprofile_uuid = oqp.uuid
where
dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
and dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and rp.language = dp.language
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectDefaultProfile" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid
WHERE
dp.language=#{language, jdbcType=VARCHAR}
AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
<select id="selectByNameAndLanguage" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
rp.name = #{name, jdbcType=VARCHAR}
and rp.language = #{language, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>
<select id="selectByNameAndLanguages" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
rp.name = #{name, jdbcType=VARCHAR}
and rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectDefaultProfiles" parameterType="map" resultType="RulesProfile">
SELECT
<include refid="profilesColumns"/>
FROM rules_profiles p
INNER JOIN default_qprofiles dp on p.kee=dp.qprofile_uuid
WHERE
dp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
AND dp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
<select id="selectByUuid" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
oqp.uuid = #{uuid, jdbcType=VARCHAR}
</select>

<select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM projects pj
JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
<select id="selectByUuids" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
oqp.uuid in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid}</foreach>
</select>

<select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pp.profile_key IS NULL
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
<select id="selectByLanguage" parameterType="String" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
rp.language = #{language, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileKey, jdbcType=VARCHAR}
WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
<select id="selectChildren" parameterType="string" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
where
oqp.parent_uuid = #{uuid, jdbcType=VARCHAR}
ORDER BY rp.name
</select>

<select id="countProjectsByProfileKey" resultType="KeyLongValue" parameterType="map">
select pp.profile_key as "key", count(projects.id) as "value"
from projects projects
inner join project_qprofiles pp ON pp.project_uuid = projects.uuid
inner join rules_profiles prof ON pp.profile_key = prof.kee
where projects.enabled = ${_true}
and prof.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
group by pp.profile_key
<select id="countProjectsByProfileUuid" resultType="KeyLongValue" parameterType="map">
select pqp.profile_key as "key", count(pj.uuid) as "value"
from projects pj
inner join project_qprofiles pqp on pqp.project_uuid = pj.uuid
inner join org_qprofiles oqp on oqp.uuid = pqp.profile_key
where
pj.enabled = ${_true}
and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
and oqp.organization_uuid = pj.organization_uuid
group by pqp.profile_key
</select>

<select id="selectAssociatedToProjectUuidAndLanguage" parameterType="map" resultType="RulesProfile">
<select id="selectAssociatedToProjectUuidAndLanguage" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="profilesColumns"/>
from rules_profiles p
inner join project_qprofiles pp ON pp.profile_key = p.kee
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
p.language = #{language, jdbcType=VARCHAR}
and pp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
rp.language = #{language, jdbcType=VARCHAR}
and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<select id="selectAssociatedToProjectUuidAndLanguages" parameterType="map" resultType="RulesProfile">
<select id="selectAssociatedToProjectUuidAndLanguages" parameterType="map" resultType="org.sonar.db.qualityprofile.QProfileDto">
select
<include refid="profilesColumns"/>
from rules_profiles p
inner join project_qprofiles pq ON pq.profile_key = p.kee
<include refid="qProfileColumns"/>
from org_qprofiles oqp
inner join rules_profiles rp on oqp.rules_profile_uuid = rp.kee
inner join project_qprofiles pqp ON pqp.profile_key = oqp.uuid
where
p.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
and pq.project_uuid = #{projectUuid, jdbcType=VARCHAR}
and p.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
rp.language in <foreach collection="languages" open="(" close=")" item="language" separator=",">#{language, jdbcType=VARCHAR}</foreach>
and pqp.project_uuid = #{projectUuid, jdbcType=VARCHAR}
and oqp.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</select>

<insert id="insertProjectProfileAssociation" useGeneratedKeys="false">
@@ -213,40 +238,86 @@
<update id="updateProjectProfileAssociation">
update project_qprofiles
set
profile_key = #{profileUuid, jdbcType=VARCHAR}
profile_key = #{profileUuid, jdbcType=VARCHAR}
where
project_uuid = #{projectUuid, jdbcType=VARCHAR}
and profile_key = #{oldProfileUuid, jdbcType=VARCHAR}
project_uuid = #{projectUuid, jdbcType=VARCHAR}
and profile_key = #{oldProfileUuid, jdbcType=VARCHAR}
</update>

<update id="deleteProjectProfileAssociation">
DELETE FROM project_qprofiles
WHERE project_uuid=#{projectUuid, jdbcType=VARCHAR} AND profile_key=#{profileKey, jdbcType=VARCHAR}
</update>
<delete id="deleteProjectProfileAssociation">
delete from project_qprofiles
where
project_uuid = #{projectUuid, jdbcType=VARCHAR}
and profile_key=#{profileUuid, jdbcType=VARCHAR}
</delete>

<update id="deleteProjectAssociationByProfileKeys" parameterType="String">
<delete id="deleteProjectAssociationByProfileUuids" parameterType="String">
delete from project_qprofiles
where profile_key in
<foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">
#{profileKey, jdbcType=VARCHAR}
<foreach collection="profileUuids" open="(" close=")" item="profileUuid" separator=",">
#{profileUuid, jdbcType=VARCHAR}
</foreach>
</update>
</delete>

<select id="selectSelectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
select
pp.id as id,
pj.id as projectId,
pj.uuid as projectUuid,
pj.kee as projectKey,
pj.name as projectName,
pp.profile_key as profileKey
from projects pj
inner join project_qprofiles pp ON pp.project_uuid = pj.uuid and pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
where
pj.scope = 'PRJ'
and pj.qualifier = 'TRK'
and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
order by pj.name ASC
</select>

<select id="selectOutdatedProfiles" parameterType="map" resultType="string">
select rp.kee
from rules_profiles rp
inner join organizations o on o.uuid = rp.organization_uuid
where rp.language = #{language, jdbcType=VARCHAR}
<select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pp.profile_key IS NULL
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
</select>

<select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
SELECT pp.id as id, pj.id as projectId, pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
</select>

<select id="selectUuidsOfCustomQProfiles" parameterType="map" resultType="string">
select oqp.uuid
from org_qprofiles oqp
inner join organizations o on o.uuid = oqp.organization_uuid
inner join rules_profiles rp on rp.kee = oqp.rules_profile_uuid
where
rp.language = #{language, jdbcType=VARCHAR}
and rp.name = #{name, jdbcType=VARCHAR}
and rp.is_built_in = ${_false}
</select>

<update id="rename" parameterType="map">
<update id="renameRulesProfiles" parameterType="map">
update rules_profiles
set
name = #{newName, jdbcType=VARCHAR},
updated_at = #{updatedAt, jdbcType=TIMESTAMP}
where kee in <foreach collection="profileKeys" open="(" close=")" item="profileKey" separator=",">#{profileKey, jdbcType=VARCHAR}</foreach>
where
kee in <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
</update>
</mapper>


+ 2
- 2
server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java 파일 보기

@@ -41,7 +41,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.Oracle;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupTesting;
import org.sonar.db.user.UserDto;
@@ -877,7 +877,7 @@ public class OrganizationDaoTest {
public void selectWithoutQualityProfile_returns_() {
OrganizationDto orgWithoutAnyProfiles = dbTester.organizations().insert();
OrganizationDto orgWithProfiles = dbTester.organizations().insert();
RulesProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles);
QProfileDto profile = dbTester.qualityProfiles().insert(orgWithProfiles);

assertThat(underTest.selectWithoutQualityProfile(dbSession, "js", "foo"))
.extracting(OrganizationDto::getUuid).containsExactlyInAnyOrder(orgWithoutAnyProfiles.getUuid(), orgWithProfiles.getUuid());

+ 3
- 3
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleDaoTest.java 파일 보기

@@ -63,8 +63,8 @@ public class ActiveRuleDaoTest {

private OrganizationDto organization = OrganizationTesting.newOrganizationDto();

private RulesProfileDto profile1 = RulesProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
private RulesProfileDto profile2 = RulesProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");
private QProfileDto profile1 = QProfileDto.createFor("qp1").setOrganizationUuid(organization.getUuid()).setName("QProfile1");
private QProfileDto profile2 = QProfileDto.createFor("qp2").setOrganizationUuid(organization.getUuid()).setName("QProfile2");

private RuleDefinitionDto rule1 = RuleTesting.newRule(RuleTesting.XOO_X1);
private RuleDefinitionDto rule2 = RuleTesting.newRule(RuleTesting.XOO_X2);
@@ -334,7 +334,7 @@ public class ActiveRuleDaoTest {
assertThat(dbTester.countRowsOfTable(dbSession, "active_rules")).isEqualTo(1);
}

private static ActiveRuleDto newRow(RulesProfileDto profile, RuleDefinitionDto rule) {
private static ActiveRuleDto newRow(QProfileDto profile, RuleDefinitionDto rule) {
return createFor(profile, rule).setSeverity(BLOCKER);
}


+ 24
- 14
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/DefaultQProfileDaoTest.java 파일 보기

@@ -20,6 +20,7 @@
package org.sonar.db.qualityprofile;

import java.util.List;
import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
@@ -42,7 +43,7 @@ public class DefaultQProfileDaoTest {
@Test
public void insertOrUpdate_inserts_row_when_does_not_exist() {
OrganizationDto org = dbTester.organizations().insert();
RulesProfileDto profile = dbTester.qualityProfiles().insert(org);
QProfileDto profile = dbTester.qualityProfiles().insert(org);
DefaultQProfileDto dto = DefaultQProfileDto.from(profile);

underTest.insertOrUpdate(dbSession, dto);
@@ -69,7 +70,7 @@ public class DefaultQProfileDaoTest {
dbSession.commit();

assertThat(countRows()).isEqualTo(1);
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, dto.getLanguage())).hasValue(newQProfileUuid);
assertThat(selectUuidOfDefaultProfile(org, dto.getLanguage())).hasValue(newQProfileUuid);
}

@Test
@@ -85,18 +86,18 @@ public class DefaultQProfileDaoTest {
dbSession.commit();

assertThat(countRows()).isEqualTo(2);
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org1, "java")).isEmpty();
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org1, "js")).hasValue("u2");
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org2, "java")).isEmpty();
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org2, "js")).hasValue("u4");
assertThat(selectUuidOfDefaultProfile(org1, "java")).isEmpty();
assertThat(selectUuidOfDefaultProfile(org1, "js")).hasValue("u2");
assertThat(selectUuidOfDefaultProfile(org2, "java")).isEmpty();
assertThat(selectUuidOfDefaultProfile(org2, "js")).hasValue("u4");
}

@Test
public void selectExistingQProfileUuids_filters_defaults() {
OrganizationDto org = dbTester.organizations().insert();
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().markAsDefault(profile1);
QProfileDto profile1 = dbTester.qualityProfiles().insert(org);
QProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().setAsDefault(profile1);

List<String> profileUuids = asList(profile1.getKee(), profile2.getKee(), "other");
assertThat(underTest.selectExistingQProfileUuids(dbSession, org.getUuid(), profileUuids))
@@ -106,21 +107,30 @@ public class DefaultQProfileDaoTest {
@Test
public void isDefault_returns_true_if_profile_is_marked_as_default() {
OrganizationDto org = dbTester.organizations().insert();
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(org);
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().markAsDefault(profile1);
QProfileDto profile1 = dbTester.qualityProfiles().insert(org);
QProfileDto profile2 = dbTester.qualityProfiles().insert(org);
dbTester.qualityProfiles().setAsDefault(profile1);

assertThat(underTest.isDefault(dbSession, org.getUuid(), profile1.getKee())).isTrue();
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile2.getKee())).isFalse();
assertThat(underTest.isDefault(dbSession, org.getUuid(), "does_not_exist")).isFalse();
}

private void assertThatIsDefault(OrganizationDto org, RulesProfileDto profile) {
assertThat(dbTester.qualityProfiles().selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee());
private void assertThatIsDefault(OrganizationDto org, QProfileDto profile) {
assertThat(selectUuidOfDefaultProfile(org, profile.getLanguage())).hasValue(profile.getKee());
assertThat(underTest.isDefault(dbSession, org.getUuid(), profile.getKee())).isTrue();
}

private int countRows() {
return dbTester.countRowsOfTable("default_qprofiles");
}

private Optional<String> selectUuidOfDefaultProfile(OrganizationDto org, String language) {
return dbTester.select("select qprofile_uuid as \"profileUuid\" " +
" from default_qprofiles " +
" where organization_uuid='" + org.getUuid() + "' and language='" + language + "'")
.stream()
.findFirst()
.map(m -> (String) m.get("profileUuid"));
}
}

+ 5
- 13
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileChangeDaoTest.java 파일 보기

@@ -88,14 +88,6 @@ public class QProfileChangeDaoTest {
assertThat(row.get("changeData")).isNull();
}

@Test
public void insert_throws_ISE_if_key_is_already_set() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Key of QProfileChangeDto must be set by DAO only. Got C1.");

underTest.insert(dbSession, new QProfileChangeDto().setKey("C1"));
}

@Test
public void insert_throws_ISE_if_date_is_already_set() {
expectedException.expect(IllegalStateException.class);
@@ -211,8 +203,8 @@ public class QProfileChangeDaoTest {
insertChange("P1", "ACTIVATED", null, null);// key: C1
insertChange("P1", "ACTIVATED", null, null);// key: C2

assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(2);
assertThat(underTest.countForProfileKey(dbSession, "P2")).isEqualTo(0);
assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(2);
assertThat(underTest.countForProfileUuid(dbSession, "P2")).isEqualTo(0);
}

@Test
@@ -224,8 +216,8 @@ public class QProfileChangeDaoTest {

underTest.deleteByProfileKeys(dbSession, asList("P1"));

assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(0);
assertThat(underTest.countForProfileKey(dbSession, "P2")).isEqualTo(1);
assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(0);
assertThat(underTest.countForProfileUuid(dbSession, "P2")).isEqualTo(1);
}

@Test
@@ -235,7 +227,7 @@ public class QProfileChangeDaoTest {

underTest.deleteByProfileKeys(dbSession, asList("does_not_exist"));

assertThat(underTest.countForProfileKey(dbSession, "P1")).isEqualTo(1);
assertThat(underTest.countForProfileUuid(dbSession, "P1")).isEqualTo(1);
}

private void insertChange(String profileKey, String type, @Nullable String login, @Nullable String data) {

+ 350
- 198
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java 파일 보기

@@ -19,10 +19,12 @@
*/
package org.sonar.db.qualityprofile;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import org.assertj.core.data.MapEntry;
import org.junit.After;
import org.junit.Before;
@@ -55,7 +57,6 @@ public class QualityProfileDaoTest {
public DbTester dbTester = DbTester.create(system);

private DbSession dbSession = dbTester.getSession();
private QualityProfileDbTester qualityProfileDb = new QualityProfileDbTester(dbTester);
private QualityProfileDao underTest = dbTester.getDbClient().qualityProfileDao();
private OrganizationDto organization;

@@ -66,90 +67,109 @@ public class QualityProfileDaoTest {
}

@After
public void tearDown() {
// minor optimization, no need to commit pending operations
public void deleteData() {
dbSession.rollback();
}

@Test
public void insert() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

RulesProfileDto dto = RulesProfileDto.createFor("abcde")
public void test_insert() {
QProfileDto dto = QProfileDto.createFor("theUuid")
.setOrganizationUuid(organization.getUuid())
.setName("ABCDE")
.setLanguage("xoo")
.setName("theName")
.setLanguage("theLang")
.setLastUsed(1_000L)
.setParentKee("theParentUuid")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(true);

underTest.insert(dbTester.getSession(), dto);
dbTester.commit();
underTest.insert(dbSession, dto);

dbTester.assertDbUnit(getClass(), "insert-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
QProfileDto reloaded = underTest.selectByUuid(dbSession, dto.getKee());
assertThat(reloaded.getKee()).isEqualTo(dto.getKee());
assertThat(reloaded.getId()).isNotNull().isNotZero();
assertThat(reloaded.getLanguage()).isEqualTo(dto.getLanguage());
assertThat(reloaded.getName()).isEqualTo(dto.getName());
assertThat(reloaded.getLastUsed()).isEqualTo(dto.getLastUsed());
assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(dto.getRulesUpdatedAt());
assertThat(reloaded.getParentKee()).isEqualTo(dto.getParentKee());
assertThat(reloaded.getOrganizationUuid()).isEqualTo(dto.getOrganizationUuid());
assertThat(reloaded.isBuiltIn()).isEqualTo(dto.isBuiltIn());
}

@Test
public void update() {
dbTester.prepareDbUnit(getClass(), "shared.xml");

RulesProfileDto dto = RulesProfileDto.createFor("key")
.setId(1)
public void test_update() {
QProfileDto initial = QProfileDto.createFor("theUuid")
.setOrganizationUuid(organization.getUuid())
.setName("New Name")
.setLanguage("js")
.setParentKee("fghij")
.setIsBuiltIn(false);

underTest.update(dbSession, dto);
dbSession.commit();

dbTester.assertDbUnit(getClass(), "update-result.xml", new String[] {"created_at", "updated_at", "rules_updated_at"}, "rules_profiles");
.setName("theName")
.setLanguage("theLang")
.setLastUsed(1_000L)
.setParentKee("theParentUuid")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(true);
underTest.insert(dbSession, initial);

QProfileDto update = QProfileDto.createFor(initial.getKee())
.setName("theNewName")
.setLanguage("theNewLang")
.setLastUsed(11_000L)
.setParentKee("theNewParentUuid")
.setUserUpdatedAt(12_000L)
.setRulesUpdatedAt("2017-06-01")
.setIsBuiltIn(false)

// field that cannot be changed
.setOrganizationUuid("theNewOrg");
underTest.update(dbSession, update);

QProfileDto reloaded = underTest.selectByUuid(dbSession, initial.getKee());
assertThat(reloaded.getKee()).isEqualTo(initial.getKee());
assertThat(reloaded.getOrganizationUuid()).isEqualTo(initial.getOrganizationUuid());

// updated fields
assertThat(reloaded.getLanguage()).isEqualTo(update.getLanguage());
assertThat(reloaded.getName()).isEqualTo(update.getName());
assertThat(reloaded.getLastUsed()).isEqualTo(update.getLastUsed());
assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(update.getRulesUpdatedAt());
assertThat(reloaded.getParentKee()).isEqualTo(update.getParentKee());
assertThat(reloaded.isBuiltIn()).isEqualTo(update.isBuiltIn());
}

@Test
public void test_deleteByKeys() {
RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto p3 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
public void test_deleteByUuids() {
QProfileDto p1 = dbTester.qualityProfiles().insert(organization);
QProfileDto p2 = dbTester.qualityProfiles().insert(organization);
QProfileDto p3 = dbTester.qualityProfiles().insert(organization);

underTest.deleteByKeys(dbSession, asList(p1.getKee(), p3.getKee(), "does_not_exist"));
underTest.deleteByUuids(dbSession, asList(p1.getKee(), p3.getKee(), "does_not_exist"));

List<Map<String, Object>> keysInDb = dbTester.select(dbSession, "select kee as \"key\" from rules_profiles");
assertThat(keysInDb).hasSize(1);
assertThat(keysInDb.get(0).get("key")).isEqualTo(p2.getKee());
List<QProfileDto> profiles = underTest.selectAll(dbSession, organization);
assertThat(profiles).extracting(QProfileDto::getKee).containsExactly(p2.getKee());
}

@Test
public void deleteByKeys_does_nothing_if_empty_keys() {
RulesProfileDto p1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
public void deleteByUuids_does_nothing_if_empty_uuids() {
dbTester.qualityProfiles().insert(organization);

underTest.deleteByKeys(dbSession, Collections.emptyList());
underTest.deleteByUuids(dbSession, Collections.emptyList());

assertThat(dbTester.countRowsOfTable(dbSession, "rules_profiles")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable(dbSession, "org_qprofiles")).isEqualTo(1);
}

@Test
public void deleteProjectAssociationsByProfileKeys_does_nothing_if_empty_keys() {
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
ComponentDto project1 = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
underTest.deleteProjectAssociationsByProfileKeys(dbSession, Collections.emptyList());
assertThat(dbTester.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1);
}
public void test_deleteProjectAssociationsByProfileUuids() {
QProfileDto profile1 = dbTester.qualityProfiles().insert(organization);
QProfileDto profile2 = dbTester.qualityProfiles().insert(organization);
ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
dbTester.qualityProfiles().associateWithProject(project1, profile1);
dbTester.qualityProfiles().associateWithProject(project2, profile1);
dbTester.qualityProfiles().associateWithProject(project3, profile2);

@Test
public void deleteProjectAssociationsByProfileKeys_deletes_rows_from_table_project_profiles() {
RulesProfileDto profile1 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
RulesProfileDto profile2 = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
ComponentDto project1 = dbTester.components().insertPrivateProject();
ComponentDto project2 = dbTester.components().insertPrivateProject();
ComponentDto project3 = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profile1);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profile1);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project3, profile2);

underTest.deleteProjectAssociationsByProfileKeys(dbSession, asList(profile1.getKee(), "does_not_exist"));
underTest.deleteProjectAssociationsByProfileUuids(dbSession, asList(profile1.getKee(), "does_not_exist"));

List<Map<String, Object>> rows = dbTester.select(dbSession, "select project_uuid as \"projectUuid\", profile_key as \"profileKey\" from project_qprofiles");
assertThat(rows).hasSize(1);
@@ -158,103 +178,148 @@ public class QualityProfileDaoTest {
}

@Test
public void find_all() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
public void deleteProjectAssociationsByProfileUuids_does_nothing_if_empty_uuids() {
QProfileDto profile = dbTester.qualityProfiles().insert(organization);
ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.qualityProfiles().associateWithProject(project, profile);

List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList());

assertThat(dtos).hasSize(2);
assertThat(dbTester.countRowsOfTable(dbSession, "project_qprofiles")).isEqualTo(1);
}

RulesProfileDto dto1 = dtos.get(0);
assertThat(dto1.getId()).isEqualTo(1);
assertThat(dto1.getName()).isEqualTo("Sonar Way");
assertThat(dto1.getLanguage()).isEqualTo("java");
assertThat(dto1.getParentKee()).isNull();
assertThat(dto1.isBuiltIn()).isTrue();

RulesProfileDto dto2 = dtos.get(1);
assertThat(dto2.getId()).isEqualTo(2);
assertThat(dto2.getName()).isEqualTo("Sonar Way");
assertThat(dto2.getLanguage()).isEqualTo("js");
assertThat(dto2.getParentKee()).isNull();
assertThat(dto2.isBuiltIn()).isFalse();
@Test
public void test_selectAll() {
List<QProfileDto> sharedData = createSharedData();

List<QProfileDto> reloadeds = underTest.selectAll(dbSession, organization);

assertThat(reloadeds).hasSize(sharedData.size());

IntStream.range(1, reloadeds.size())
.forEach(
i -> {
QProfileDto reloaded = reloadeds.get(i - 1);
QProfileDto original = sharedData.get(i - 1);

assertThat(reloaded.getId()).isEqualTo(original.getId());
assertThat(reloaded.getName()).isEqualTo(original.getName());
assertThat(reloaded.getKee()).isEqualTo(original.getKee());
assertThat(reloaded.getOrganizationUuid()).isEqualTo(original.getOrganizationUuid());
assertThat(reloaded.getLanguage()).isEqualTo(original.getLanguage());
assertThat(reloaded.getParentKee()).isEqualTo(original.getParentKee());
assertThat(reloaded.getRulesUpdatedAt()).isEqualTo(original.getRulesUpdatedAt());
assertThat(reloaded.getLastUsed()).isEqualTo(original.getLastUsed());
assertThat(reloaded.getUserUpdatedAt()).isEqualTo(original.getUserUpdatedAt());
assertThat(reloaded.isBuiltIn()).isEqualTo(original.isBuiltIn());
}
);
}

@Test
public void find_all_is_sorted_by_profile_name() {
dbTester.prepareDbUnit(getClass(), "select_all_is_sorted_by_profile_name.xml");
QProfileDto dto1 = QProfileDto.createFor("js_first")
.setOrganizationUuid(organization.getUuid())
.setName("First")
.setLanguage("js")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, dto1);

QProfileDto dto2 = QProfileDto.createFor("js_second")
.setOrganizationUuid(organization.getUuid())
.setName("Second")
.setLanguage("js")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, dto2);

QProfileDto dto3 = QProfileDto.createFor("js_third")
.setOrganizationUuid(organization.getUuid())
.setName("Third")
.setLanguage("js")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, dto3);

List<RulesProfileDto> dtos = underTest.selectAll(dbTester.getSession(), organization);
List<QProfileDto> dtos = underTest.selectAll(dbSession, organization);

assertThat(dtos).hasSize(3);
assertThat(dtos.get(0).getName()).isEqualTo("First");
assertThat(dtos.get(1).getName()).isEqualTo("Second");
assertThat(dtos.get(2).getName()).isEqualTo("Third");

underTest.deleteByUuids(dbSession, Arrays.asList("js_first", "js_second", "js_third"));
}

@Test
public void get_default_profile() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
List<QProfileDto> sharedData = createSharedData();

RulesProfileDto java = underTest.selectDefaultProfile(dbTester.getSession(), organization, "java");
QProfileDto java = underTest.selectDefaultProfile(dbSession, organization, "java");
assertThat(java).isNotNull();
assertThat(java.getKee()).isEqualTo("java_sonar_way");

assertThat(underTest.selectDefaultProfile(dbTester.getSession(), dbTester.organizations().insert(), "java")).isNull();
assertThat(underTest.selectDefaultProfile(dbTester.getSession(), organization, "js")).isNull();
assertThat(underTest.selectDefaultProfile(dbSession, dbTester.organizations().insert(), "java")).isNull();
assertThat(underTest.selectDefaultProfile(dbSession, organization, "js")).isNull();
}

@Test
public void get_default_profiles() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
List<QProfileDto> sharedData = createSharedData();

List<RulesProfileDto> java = underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("java"));
assertThat(java).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
List<QProfileDto> java = underTest.selectDefaultProfiles(dbSession, organization, singletonList("java"));
assertThat(java).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");

assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, singletonList("js"))).isEmpty();
assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, of("java", "js"))).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
assertThat(underTest.selectDefaultProfiles(dbTester.getSession(), organization, of("js", "java"))).extracting(RulesProfileDto::getKee).containsOnly("java_sonar_way");
assertThat(underTest.selectDefaultProfiles(dbSession, organization, singletonList("js"))).isEmpty();
assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("java", "js"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");
assertThat(underTest.selectDefaultProfiles(dbSession, organization, of("js", "java"))).extracting(QProfileDto::getKee).containsOnly("java_sonar_way");
}

@Test
public void get_by_name_and_language() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
List<QProfileDto> sharedData = createSharedData();

RulesProfileDto dto = underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession());
assertThat(dto.getId()).isEqualTo(1);
QProfileDto dto = underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "java");
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();

assertThat(underTest.selectByNameAndLanguage(organization, "Sonar Way", "java", dbTester.getSession())).isNotNull();
assertThat(underTest.selectByNameAndLanguage(organization, "Sonar Way", "unknown", dbTester.getSession())).isNull();
assertThat(underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "java")).isNotNull();
assertThat(underTest.selectByNameAndLanguage(dbSession, organization, "Sonar Way", "unknown")).isNull();
}

@Test
public void get_by_name_and_languages() {
dbTester.prepareDbUnit(getClass(), "shared.xml");
createSharedData();

List<RulesProfileDto> dtos = underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("java"), dbTester.getSession());
List<QProfileDto> dtos = underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", singletonList("java"));
assertThat(dtos).hasSize(1);
RulesProfileDto dto = dtos.iterator().next();
assertThat(dto.getId()).isEqualTo(1);
QProfileDto dto = dtos.iterator().next();
assertThat(dto.getName()).isEqualTo("Sonar Way");
assertThat(dto.getLanguage()).isEqualTo("java");
assertThat(dto.getParentKee()).isNull();

assertThat(underTest.selectByNameAndLanguages(organization, "Sonar Way", singletonList("unknown"), dbTester.getSession())).isEmpty();
assertThat(underTest.selectByNameAndLanguages(organization, "Sonar Way", of("java", "unknown"), dbTester.getSession())).extracting("id").containsOnly(1);
assertThat(underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", singletonList("unknown"))).isEmpty();
assertThat(underTest.selectByNameAndLanguages(dbSession, organization, "Sonar Way", of("java", "unknown")))
.extracting(QProfileDto::getKee).containsOnly(dto.getKee());
}

@Test
public void should_find_by_language() {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
List<QProfileDto> results = underTest.selectByLanguage(dbSession, organization, profile.getLanguage());
assertThat(results).hasSize(1);
RulesProfileDto result = results.get(0);
QProfileDto result = results.get(0);

assertThat(result.getId()).isEqualTo(profile.getId());
assertThat(result.getName()).isEqualTo(profile.getName());
@@ -265,60 +330,123 @@ public class QualityProfileDaoTest {

@Test
public void should_not_find_by_language_in_wrong_organization() {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
List<QProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage());
assertThat(results).isEmpty();
}

@Test
public void should_not_find_by_language_with_wrong_language() {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
underTest.insert(dbSession, profile);

List<RulesProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
List<QProfileDto> results = underTest.selectByLanguage(dbSession, organization, "another language");
assertThat(results).isEmpty();
}


@Test
public void find_children() {
dbTester.prepareDbUnit(getClass(), "inheritance.xml");
QProfileDto original1 = QProfileDto.createFor("java_child1")
.setOrganizationUuid(organization.getUuid())
.setName("Child1")
.setLanguage("java")
.setLastUsed(1_000L)
.setParentKee("java_parent")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original1);

QProfileDto original2 = QProfileDto.createFor("java_child2")
.setOrganizationUuid(organization.getUuid())
.setName("Child2")
.setLanguage("java")
.setLastUsed(1_000L)
.setParentKee("java_parent")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original2);

QProfileDto original3 = QProfileDto.createFor("java_parent")
.setOrganizationUuid(organization.getUuid())
.setName("Parent")
.setLanguage("java")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original3);

QProfileDto original4 = QProfileDto.createFor("js_child1")
.setOrganizationUuid(organization.getUuid())
.setName("Child1")
.setLanguage("js")
.setLastUsed(1_000L)
.setParentKee("js_parent")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original4);

List<RulesProfileDto> dtos = underTest.selectChildren(dbTester.getSession(), "java_parent");
QProfileDto original5 = QProfileDto.createFor("js_child2")
.setOrganizationUuid(organization.getUuid())
.setName("Child2")
.setLanguage("js")
.setLastUsed(1_000L)
.setParentKee("js_parent")
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original5);

QProfileDto original6 = QProfileDto.createFor("js_parent")
.setOrganizationUuid(organization.getUuid())
.setName("Parent")
.setLanguage("js")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(false);
underTest.insert(dbSession, original6);

List<QProfileDto> dtos = underTest.selectChildren(dbSession, "java_parent");

assertThat(dtos).hasSize(2);

RulesProfileDto dto1 = dtos.get(0);
assertThat(dto1.getId()).isEqualTo(1);
QProfileDto dto1 = dtos.get(0);
assertThat(dto1.getName()).isEqualTo("Child1");
assertThat(dto1.getLanguage()).isEqualTo("java");
assertThat(dto1.getParentKee()).isEqualTo("java_parent");

RulesProfileDto dto2 = dtos.get(1);
assertThat(dto2.getId()).isEqualTo(2);
QProfileDto dto2 = dtos.get(1);
assertThat(dto2.getName()).isEqualTo("Child2");
assertThat(dto2.getLanguage()).isEqualTo("java");
assertThat(dto2.getParentKee()).isEqualTo("java_parent");

underTest.deleteByUuids(dbSession, Arrays.asList("java_parent", "java_child1", "java_child2", "js_parent", "js_child1", "js_child2"));
}

@Test
public void countProjectsByProfileKey() {
RulesProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
RulesProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
QProfileDto profileWithoutProjects = dbTester.qualityProfiles().insert(organization);
QProfileDto profileWithProjects = dbTester.qualityProfiles().insert(organization);
ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, profileWithProjects);
dbTester.qualityProfiles().associateProjectWithQualityProfile(project2, profileWithProjects);
dbTester.qualityProfiles().associateWithProject(project1, profileWithProjects);
dbTester.qualityProfiles().associateWithProject(project2, profileWithProjects);

OrganizationDto otherOrg = dbTester.organizations().insert();
RulesProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
QProfileDto profileInOtherOrg = dbTester.qualityProfiles().insert(otherOrg);
ComponentDto projectInOtherOrg = dbTester.components().insertPrivateProject(otherOrg);
dbTester.qualityProfiles().associateProjectWithQualityProfile(projectInOtherOrg, profileInOtherOrg);
dbTester.qualityProfiles().associateWithProject(projectInOtherOrg, profileInOtherOrg);

assertThat(underTest.countProjectsByProfileKey(dbTester.getSession(), organization)).containsOnly(
assertThat(underTest.countProjectsByProfileUuid(dbSession, organization)).containsOnly(
MapEntry.entry(profileWithProjects.getKee(), 2L));
}

@@ -327,17 +455,17 @@ public class QualityProfileDaoTest {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project1 = dbTester.components().insertPublicProject(org);
ComponentDto project2 = dbTester.components().insertPublicProject(org);
RulesProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, javaProfile, jsProfile);
QProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
dbTester.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);

assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "java").getKee())
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "java").getKee())
.isEqualTo(javaProfile.getKee());
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "js").getKee())
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "js").getKee())
.isEqualTo(jsProfile.getKee());
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project1, "cobol"))
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "cobol"))
.isNull();
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbTester.getSession(), project2, "java"))
assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project2, "java"))
.isNull();
}

@@ -346,19 +474,19 @@ public class QualityProfileDaoTest {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project1 = dbTester.components().insertPublicProject(org);
ComponentDto project2 = dbTester.components().insertPublicProject(org);
RulesProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
dbTester.qualityProfiles().associateProjectWithQualityProfile(project1, javaProfile, jsProfile);
QProfileDto javaProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
dbTester.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);

assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, singletonList("java")))
.extracting(RulesProfileDto::getKee).containsOnly(javaProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, singletonList("unknown")))
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, singletonList("java")))
.extracting(QProfileDto::getKee).containsOnly(javaProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, singletonList("unknown")))
.isEmpty();
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, of("java", "unknown")))
.extracting(RulesProfileDto::getKee).containsExactly(javaProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project1, of("java", "js")))
.extracting(RulesProfileDto::getKee).containsExactlyInAnyOrder(javaProfile.getKee(), jsProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbTester.getSession(), project2, singletonList("java")))
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, of("java", "unknown")))
.extracting(QProfileDto::getKee).containsExactly(javaProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project1, of("java", "js")))
.extracting(QProfileDto::getKee).containsExactlyInAnyOrder(javaProfile.getKee(), jsProfile.getKee());
assertThat(underTest.selectAssociatedToProjectUuidAndLanguages(dbSession, project2, singletonList("java")))
.isEmpty();
}

@@ -366,10 +494,10 @@ public class QualityProfileDaoTest {
public void test_updateProjectProfileAssociation() {
OrganizationDto org = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertPrivateProject(org);
RulesProfileDto javaProfile1 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
RulesProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
RulesProfileDto javaProfile2 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
qualityProfileDb.associateProjectWithQualityProfile(project, javaProfile1, jsProfile);
QProfileDto javaProfile1 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("js"));
QProfileDto javaProfile2 = dbTester.qualityProfiles().insert(org, p -> p.setLanguage("java"));
dbTester.qualityProfiles().associateWithProject(project, javaProfile1, jsProfile);

underTest.updateProjectProfileAssociation(dbSession, project, javaProfile2.getKee(), javaProfile1.getKee());

@@ -379,15 +507,15 @@ public class QualityProfileDaoTest {

@Test
public void selectByKeys() {
qualityProfileDb.insertQualityProfiles(newQualityProfileDto().setKey("qp-key-1"), newQualityProfileDto().setKee("qp-key-2"), newQualityProfileDto().setKee("qp-key-3"));
dbTester.qualityProfiles().insert(newQualityProfileDto().setKey("qp-key-1"), newQualityProfileDto().setKee("qp-key-2"), newQualityProfileDto().setKee("qp-key-3"));

assertThat(underTest.selectOrFailByKey(dbSession, "qp-key-1")).isNotNull();
assertThat(underTest.selectByKey(dbSession, "qp-key-1")).isNotNull();
assertThat(underTest.selectByKey(dbSession, "qp-key-42")).isNull();
assertThat(underTest.selectByKeys(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
assertThat(underTest.selectOrFailByUuid(dbSession, "qp-key-1")).isNotNull();
assertThat(underTest.selectByUuid(dbSession, "qp-key-1")).isNotNull();
assertThat(underTest.selectByUuid(dbSession, "qp-key-42")).isNull();
assertThat(underTest.selectByUuids(dbSession, newArrayList("qp-key-1", "qp-key-3", "qp-key-42")))
.hasSize(2)
.extracting(RulesProfileDto::getKee).containsOnlyOnce("qp-key-1", "qp-key-3");
assertThat(underTest.selectByKeys(dbSession, emptyList())).isEmpty();
.extracting(QProfileDto::getKee).containsOnlyOnce("qp-key-1", "qp-key-3");
assertThat(underTest.selectByUuids(dbSession, emptyList())).isEmpty();
}

@Test
@@ -398,23 +526,24 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile1);
QProfileDto profile1 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile1);
dbTester.qualityProfiles().associateWithProject(project1, profile1);
dbTester.qualityProfiles().associateWithProject(project2, profile1);

RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project3, profile2);
QProfileDto profile2 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile2);
dbTester.qualityProfiles().associateWithProject(project3, profile2);
QProfileDto profile3 = newQualityProfileDto();

assertThat(underTest.selectSelectedProjects(organization, profile1.getKee(), null, dbSession))
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKee()),
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), profile1.getKee()));

assertThat(underTest.selectSelectedProjects(organization, profile1.getKee(), "ect1", dbSession)).hasSize(1);
assertThat(underTest.selectSelectedProjects(organization, "unknown", null, dbSession)).isEmpty();
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, "ect1")).hasSize(1);
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile3, null)).isEmpty();
}

@Test
@@ -425,22 +554,23 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
QProfileDto profile1 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile1);
dbTester.qualityProfiles().associateWithProject(project1, profile1);

RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);
QProfileDto profile2 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile2);
dbTester.qualityProfiles().associateWithProject(project2, profile2);
QProfileDto profile3 = newQualityProfileDto();

assertThat(underTest.selectDeselectedProjects(organization, profile1.getKee(), null, dbSession))
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsExactly(
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null),
tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null));

assertThat(underTest.selectDeselectedProjects(organization, profile1.getKee(), "ect2", dbSession)).hasSize(1);
assertThat(underTest.selectDeselectedProjects(organization, "unknown", null, dbSession)).hasSize(3);
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile3, null)).hasSize(3);
}

@Test
@@ -451,23 +581,24 @@ public class QualityProfileDaoTest {
OrganizationDto organization2 = dbTester.organizations().insert();
ComponentDto project4 = dbTester.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));

RulesProfileDto profile1 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile1);
qualityProfileDb.associateProjectWithQualityProfile(project1, profile1);
QProfileDto profile1 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile1);
dbTester.qualityProfiles().associateWithProject(project1, profile1);

RulesProfileDto profile2 = newQualityProfileDto();
qualityProfileDb.insertQualityProfiles(profile2);
qualityProfileDb.associateProjectWithQualityProfile(project2, profile2);
QProfileDto profile2 = newQualityProfileDto();
dbTester.qualityProfiles().insert(profile2);
dbTester.qualityProfiles().associateWithProject(project2, profile2);
QProfileDto profile3 = newQualityProfileDto();

assertThat(underTest.selectProjectAssociations(organization, profile1.getKee(), null, dbSession))
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null))
.extracting("projectId", "projectUuid", "projectKey", "projectName", "profileKey")
.containsOnly(
tuple(project1.getId(), project1.uuid(), project1.key(), project1.name(), profile1.getKee()),
tuple(project2.getId(), project2.uuid(), project2.key(), project2.name(), null),
tuple(project3.getId(), project3.uuid(), project3.key(), project3.name(), null));

assertThat(underTest.selectProjectAssociations(organization, profile1.getKee(), "ect2", dbSession)).hasSize(1);
assertThat(underTest.selectProjectAssociations(organization, "unknown", null, dbSession)).hasSize(3);
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, "ect2")).hasSize(1);
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile3, null)).hasSize(3);
}

@Test
@@ -475,54 +606,75 @@ public class QualityProfileDaoTest {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
OrganizationDto org3 = dbTester.organizations().insert();
RulesProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
RulesProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
RulesProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo"));
RulesProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
RulesProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));
QProfileDto outdatedProfile1 = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
QProfileDto outdatedProfile2 = dbTester.qualityProfiles().insert(org2, p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
QProfileDto builtInProfile = dbTester.qualityProfiles().insert(org3, p -> p.setIsBuiltIn(true).setLanguage("java").setName("foo"));
QProfileDto differentLanguage = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
QProfileDto differentName = dbTester.qualityProfiles().insert(org1, p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));

Collection<String> keys = underTest.selectOutdatedProfiles(dbSession, "java", "foo");
Collection<String> keys = underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo");

assertThat(keys).containsExactlyInAnyOrder(outdatedProfile1.getKee(), outdatedProfile2.getKee());
}

@Test
public void selectOutdatedProfiles_returns_empty_list_if_no_match() {
assertThat(underTest.selectOutdatedProfiles(dbSession, "java", "foo")).isEmpty();
assertThat(underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo")).isEmpty();
}

@Test
public void renameAndCommit_updates_name_of_specified_profiles() {
OrganizationDto org1 = dbTester.organizations().insert();
OrganizationDto org2 = dbTester.organizations().insert();
RulesProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setName("foo"));
RulesProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setName("foo"));
RulesProfileDto bar = dbTester.qualityProfiles().insert(org1, p -> p.setName("bar"));
QProfileDto fooInOrg1 = dbTester.qualityProfiles().insert(org1, p -> p.setName("foo"));
QProfileDto fooInOrg2 = dbTester.qualityProfiles().insert(org2, p -> p.setName("foo"));
QProfileDto bar = dbTester.qualityProfiles().insert(org1, p -> p.setName("bar"));

underTest.renameAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)");
underTest.renameRulesProfilesAndCommit(dbSession, asList(fooInOrg1.getKee(), fooInOrg2.getKee()), "foo (copy)");

assertThat(underTest.selectOrFailByKey(dbSession, fooInOrg1.getKee()).getName()).isEqualTo("foo (copy)");
assertThat(underTest.selectOrFailByKey(dbSession, fooInOrg2.getKee()).getName()).isEqualTo("foo (copy)");
assertThat(underTest.selectOrFailByKey(dbSession, bar.getKee()).getName()).isEqualTo("bar");
assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg1.getKee()).getName()).isEqualTo("foo (copy)");
assertThat(underTest.selectOrFailByUuid(dbSession, fooInOrg2.getKee()).getName()).isEqualTo("foo (copy)");
assertThat(underTest.selectOrFailByUuid(dbSession, bar.getKee()).getName()).isEqualTo("bar");
}

@Test
public void renameAndCommit_does_nothing_if_empty_keys() {
OrganizationDto org = dbTester.organizations().insert();
RulesProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));
QProfileDto profile = dbTester.qualityProfiles().insert(org, p -> p.setName("foo"));

underTest.renameAndCommit(dbSession, Collections.emptyList(), "foo (copy)");
underTest.renameRulesProfilesAndCommit(dbSession, Collections.emptyList(), "foo (copy)");

assertThat(underTest.selectOrFailByKey(dbSession, profile.getKee()).getName()).isEqualTo("foo");
assertThat(underTest.selectOrFailByUuid(dbSession, profile.getKee()).getName()).isEqualTo("foo");
}

private RulesProfileDto insertQualityProfileDto(String key, String name, String language) {
RulesProfileDto dto = RulesProfileDto.createFor(key)
private List<QProfileDto> createSharedData() {
QProfileDto dto1 = QProfileDto.createFor("java_sonar_way")
.setOrganizationUuid(organization.getUuid())
.setName(name)
.setLanguage(language);
underTest.insert(dbSession, dto);
return dto;
.setName("Sonar Way")
.setLanguage("java")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(true);
underTest.insert(dbSession, dto1);

QProfileDto dto2 = QProfileDto.createFor("js_sonar_way")
.setOrganizationUuid(organization.getUuid())
.setName("Sonar Way")
.setLanguage("js")
.setLastUsed(1_000L)
.setUserUpdatedAt(2_000L)
.setRulesUpdatedAt("2017-05-31")
.setIsBuiltIn(true);
underTest.insert(dbSession, dto2);

DefaultQProfileDto defaultQProfileDto = new DefaultQProfileDto()
.setQProfileUuid(dto1.getKee())
.setLanguage(dto1.getLanguage())
.setOrganizationUuid(organization.getUuid());
dbTester.getDbClient().defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(dto1));

return Arrays.asList(dto1, dto2);
}

}

+ 39
- 49
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDbTester.java 파일 보기

@@ -22,6 +22,7 @@ package org.sonar.db.qualityprofile;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;
import org.sonar.api.rule.Severity;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
@@ -29,93 +30,82 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;

import static org.sonar.api.rule.Severity.MAJOR;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.sonar.db.qualityprofile.ActiveRuleDto.createFor;

public class QualityProfileDbTester {
private final DbTester dbTester;
private final DbClient dbClient;
private final DbSession dbSession;

public QualityProfileDbTester(DbTester dbTester) {
this.dbTester = dbTester;
this.dbClient = dbTester.getDbClient();
this.dbSession = dbTester.getSession();
}

public Optional<RulesProfileDto> selectByKey(String key) {
return Optional.ofNullable(dbClient.qualityProfileDao().selectByKey(dbSession, key));
public Optional<QProfileDto> selectByUuid(String uuid) {
return Optional.ofNullable(dbClient.qualityProfileDao().selectByUuid(dbSession, uuid));
}

/**
* Create a profile with random field values on the specified organization.
*/
@SafeVarargs
public final RulesProfileDto insert(OrganizationDto organization, Consumer<RulesProfileDto>... consumers) {
RulesProfileDto profile = QualityProfileTesting.newQualityProfileDto()
public QProfileDto insert(OrganizationDto organization) {
return insert(organization, c -> {
});
}

/**
* Create a profile with random field values on the specified organization.
*/
public QProfileDto insert(OrganizationDto organization, Consumer<QProfileDto> consumer) {
QProfileDto profile = QualityProfileTesting.newQualityProfileDto()
.setOrganizationUuid(organization.getUuid());
Arrays.stream(consumers).forEach(c -> c.accept(profile));
consumer.accept(profile);

dbClient.qualityProfileDao().insert(dbSession, profile);
dbSession.commit();
return profile;
}

public void insertQualityProfiles(RulesProfileDto qualityProfile, RulesProfileDto... qualityProfiles) {
dbClient.qualityProfileDao().insert(dbSession, qualityProfile, qualityProfiles);
dbSession.commit();
}

public RulesProfileDto insertQualityProfile(RulesProfileDto qualityProfile) {
dbClient.qualityProfileDao().insert(dbSession, qualityProfile);
public QualityProfileDbTester insert(QProfileDto profile, QProfileDto... others) {
dbClient.qualityProfileDao().insert(dbSession, profile);
Arrays.stream(others).forEach(p -> dbClient.qualityProfileDao().insert(dbSession, p));
dbSession.commit();
return qualityProfile;
return this;
}

public void insertProjectWithQualityProfileAssociations(ComponentDto project, RulesProfileDto... qualityProfiles) {
dbClient.componentDao().insert(dbSession, project);
for (RulesProfileDto qualityProfile : qualityProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, qualityProfile);
public QualityProfileDbTester associateWithProject(ComponentDto project, QProfileDto profile, QProfileDto... otherProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);
for (QProfileDto p : otherProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, p);
}
dbSession.commit();
return this;
}

public void associateProjectWithQualityProfile(ComponentDto project, RulesProfileDto... qualityProfiles) {
for (RulesProfileDto qualityProfile : qualityProfiles) {
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, qualityProfile);
}
dbSession.commit();
public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule) {
return activateRule(profile, rule, ar -> {
});
}

@SafeVarargs
public final ActiveRuleDto activateRule(RulesProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto>... consumers) {
ActiveRuleDto activeRule = createFor(profile, rule).setSeverity(MAJOR);
for (Consumer<ActiveRuleDto> consumer : consumers) {
consumer.accept(activeRule);
}
public ActiveRuleDto activateRule(QProfileDto profile, RuleDefinitionDto rule, Consumer<ActiveRuleDto> consumer) {
ActiveRuleDto activeRule = createFor(profile, rule)
.setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size())))
.setCreatedAt(nextLong())
.setUpdatedAt(nextLong());
consumer.accept(activeRule);
dbClient.activeRuleDao().insert(dbSession, activeRule);
dbSession.commit();
return activeRule;
}

public void markAsDefault(RulesProfileDto... profiles) {
for (RulesProfileDto profile : profiles) {
DefaultQProfileDto dto = new DefaultQProfileDto()
.setOrganizationUuid(profile.getOrganizationUuid())
.setLanguage(profile.getLanguage())
.setQProfileUuid(profile.getKee());
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, dto);
public QualityProfileDbTester setAsDefault(QProfileDto profile, QProfileDto... others) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
for (QProfileDto other : others) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(other));
}
dbSession.commit();
}

public Optional<String> selectUuidOfDefaultProfile(OrganizationDto org, String language) {
return dbTester.select("select qprofile_uuid as \"profileUuid\" " +
" from default_qprofiles " +
" where organization_uuid='" + org.getUuid() + "' and language='" + language + "'")
.stream()
.findFirst()
.map(m -> (String)m.get("profileUuid"));
return this;
}
}

+ 13
- 15
server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileTesting.java 파일 보기

@@ -20,25 +20,32 @@
package org.sonar.db.qualityprofile;

import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;

import static java.util.Arrays.stream;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextLong;

public class QualityProfileTesting {

public static RulesProfileDto newQualityProfileDto() {
private QualityProfileTesting() {
// prevent instantiation
}

/**
* Create an instance of {@link QProfileDto} with random field values.
*/
public static QProfileDto newQualityProfileDto() {
String uuid = Uuids.createFast();
RulesProfileDto dto = RulesProfileDto.createFor(uuid)
return QProfileDto.createFor(uuid)
.setOrganizationUuid(randomAlphanumeric(40))
.setName(uuid)
.setLanguage(randomAlphanumeric(20))
.setLastUsed(nextLong());
return dto;
}

/**
* Create an instance of {@link QProfileChangeDto} with random field values,
* except changeType which is always {@code "ACTIVATED"}.
*/
public static QProfileChangeDto newQProfileChangeDto() {
return new QProfileChangeDto()
.setKey(randomAlphanumeric(40))
@@ -47,13 +54,4 @@ public class QualityProfileTesting {
.setChangeType("ACTIVATED")
.setLogin(randomAlphanumeric(10));
}

public static void insert(DbTester dbTester, QProfileChangeDto... dtos) {
// do not use QProfileChangeDao so that generated fields key and creation date
// can be defined by tests
DbSession dbSession = dbTester.getSession();
QProfileChangeMapper mapper = dbSession.getMapper(QProfileChangeMapper.class);
stream(dtos).forEach(mapper::insert);
dbSession.commit();
}
}

+ 0
- 16
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/delete-result.xml 파일 보기

@@ -1,16 +0,0 @@
<dataset>

<rules_profiles id="2"
name="Sonar Way"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="123456789"
user_updated_at="987654321"/>

</dataset>

+ 0
- 71
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/inheritance.xml 파일 보기

@@ -1,71 +0,0 @@
<dataset>

<rules_profiles id="1"
name="Child1"
language="java"
organization_uuid="org-123"
parent_kee="java_parent"
kee="java_child1"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="2"
name="Child2"
language="java"
organization_uuid="org-123"
parent_kee="java_parent"
kee="java_child2"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="3"
name="Parent"
language="java"
organization_uuid="org-123"
parent_kee="[null]"
kee="java_parent"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<!-- Same profile for another language -->

<rules_profiles id="4"
name="Child1"
language="js"
organization_uuid="org-123"
parent_kee="js_parent"
kee="js_child1"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="5"
name="Child2"
language="js"
organization_uuid="org-123"
parent_kee="js_parent"
kee="js_child2"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="6"
name="Parent"
language="js"
organization_uuid="org-123"
parent_kee="[null]"
kee="js_parent"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

</dataset>

+ 0
- 43
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/insert-result.xml 파일 보기

@@ -1,43 +0,0 @@
<dataset>

<rules_profiles id="1"
name="Sonar Way"
language="java"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="[null]"
user_updated_at="[null]"/>

<rules_profiles id="2"
name="Sonar Way"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="123456789"
user_updated_at="987654321"/>

<rules_profiles id="3"
name="ABCDE"
language="xoo"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="abcde"
is_built_in="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="[null]"
user_updated_at="[null]"/>


</dataset>

+ 0
- 37
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml 파일 보기

@@ -1,37 +0,0 @@
<dataset>

<rules_profiles id="3"
name="Third"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_third"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="1"
name="First"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_first"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="2"
name="Second"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_second"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>


</dataset>

+ 0
- 36
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/select_by_language.xml 파일 보기

@@ -1,36 +0,0 @@
<dataset>

<rules_profiles id="1"
name="Sonar Way 1"
language="java"
organization_uuid="org-123"
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="2"
name="Sonar Way"
language="js"
organization_uuid="org-123"
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

<rules_profiles id="3"
name="Sonar Way 2"
language="java"
organization_uuid="org-123"
parent_kee="[null]"
kee="java_sonar_way2"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"/>

</dataset>

+ 0
- 37
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/shared.xml 파일 보기

@@ -1,37 +0,0 @@
<dataset>

<rules_profiles id="1"
name="Sonar Way"
language="java"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="java_sonar_way"
is_built_in="[true]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="[null]"
user_updated_at="[null]"/>

<rules_profiles id="2"
name="Sonar Way"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="123456789"
user_updated_at="987654321"/>

<default_qprofiles
organization_uuid="QualityProfileDaoTest-ORG"
language="java"
qprofile_uuid="java_sonar_way"
created_at="1000"
updated_at="2000"
/>

</dataset>

+ 0
- 28
server/sonar-db-dao/src/test/resources/org/sonar/db/qualityprofile/QualityProfileDaoTest/update-result.xml 파일 보기

@@ -1,28 +0,0 @@
<dataset>

<rules_profiles id="1"
name="New Name"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="fghij"
kee="java_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="[null]"
user_updated_at="[null]"/>

<rules_profiles id="2"
name="Sonar Way"
language="js"
organization_uuid="QualityProfileDaoTest-ORG"
parent_kee="[null]"
kee="js_sonar_way"
is_built_in="[false]"
rules_updated_at="[null]"
created_at="[null]"
updated_at="[null]"
last_used="123456789"
user_updated_at="987654321"/>
</dataset>

server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfiles.java → server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfiles.java 파일 보기

@@ -30,11 +30,11 @@ import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.new
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;

public class CreateTableQProfiles extends DdlChange {
public class CreateTableOrgQProfiles extends DdlChange {

private static final String TABLE_NAME = "qprofiles";
private static final String TABLE_NAME = "org_qprofiles";

public CreateTableQProfiles(Database db) {
public CreateTableOrgQProfiles(Database db) {
super(db);
}

@@ -46,21 +46,21 @@ public class CreateTableQProfiles extends DdlChange {
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
VarcharColumnDef rulesProfileUuid = newVarcharColumnDefBuilder()
.setColumnName("rules_profile_uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build();
context.execute(
new CreateTableBuilder(getDialect(), TABLE_NAME)
.addPkColumn(newVarcharColumnDefBuilder()
.setColumnName("uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build())
.addColumn(organizationColumn)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("rules_profile_uuid")
.setLimit(UUID_SIZE)
.setIsNullable(false)
.setIgnoreOracleUnit(true)
.build())
.addColumn(rulesProfileUuid)
.addColumn(newVarcharColumnDefBuilder()
.setColumnName("parent_uuid")
.setLimit(UUID_SIZE)
@@ -83,5 +83,12 @@ public class CreateTableQProfiles extends DdlChange {
.setName("qprofiles_org_uuid")
.addColumn(organizationColumn)
.build());

context.execute(
new CreateIndexBuilder(getDialect())
.setTable(TABLE_NAME)
.setName("qprofiles_rp_uuid")
.addColumn(rulesProfileUuid)
.build());
}
}

+ 2
- 1
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java 파일 보기

@@ -49,6 +49,7 @@ public class DbVersion65 implements DbVersion {
.add(1720, "Populate table default_qprofiles", PopulateTableDefaultQProfiles.class)
.add(1721, "Drop rules_profiles.is_default", DropIsDefaultColumnFromRulesProfiles.class)
.add(1722, "Create table qprofiles", CreateTableQProfiles.class)
.add(1723, "Populate table qprofiles", PopulateQProfiles.class);
.add(1723, "Populate table qprofiles", PopulateQProfiles.class)
.add(1724, "Drop columns organization_uuid and parent_kee from rules_profiles", DropOrgUuidAndParentKeeFromRulesProfiles.class);
}
}

+ 41
- 0
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfiles.java 파일 보기

@@ -0,0 +1,41 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.sonar.server.platform.db.migration.version.v65;

import java.sql.SQLException;
import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;

public class DropOrgUuidAndParentKeeFromRulesProfiles extends DdlChange {

private static final String TABLE_NAME = "rules_profiles";

public DropOrgUuidAndParentKeeFromRulesProfiles(Database db) {
super(db);
}

@Override
public void execute(Context context) throws SQLException {
context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "organization_uuid").build());
context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, "parent_kee").build());
}
}

server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfiles.java → server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfiles.java 파일 보기

@@ -26,11 +26,11 @@ import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;

public class PopulateQProfiles extends DataChange {
public class PopulateOrgQProfiles extends DataChange {

private final System2 system2;

public PopulateQProfiles(Database db, System2 system2) {
public PopulateOrgQProfiles(Database db, System2 system2) {
super(db);
this.system2 = system2;
}
@@ -41,15 +41,19 @@ public class PopulateQProfiles extends DataChange {

MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select p.kee, p.organization_uuid, p.parent_kee from rules_profiles p " +
"where not exists ( select qp.uuid from qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )");
massUpdate.update("insert into qprofiles" +
"where not exists ( select qp.uuid from org_qprofiles qp where qp.uuid = p.kee and qp.organization_uuid = p.organization_uuid )");
massUpdate.update("insert into org_qprofiles" +
" (uuid, organization_uuid, rules_profile_uuid, parent_uuid, created_at, updated_at) values (?, ?, ?, ?, ?, ?)");
massUpdate.rowPluralName("qprofiles");
massUpdate.rowPluralName("org_qprofiles");
massUpdate.execute((row, update) -> {
update.setString(1, row.getString(1));
update.setString(2, row.getString(2));
update.setString(3, row.getString(1));
update.setString(4, row.getString(3));
String uuid = row.getString(1);
String organizationUuid = row.getString(2);
String parentUuid = row.getString(3);

update.setString(1, uuid);
update.setString(2, organizationUuid);
update.setString(3, uuid);
update.setString(4, parentUuid);
update.setLong(5, now);
update.setLong(6, now);
return true;

server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest.java → server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest.java 파일 보기

@@ -29,16 +29,16 @@ import org.sonar.db.CoreDbTester;
import static org.assertj.core.api.Assertions.assertThat;


public class CreateTableQProfilesTest {
public class CreateTableOrgQProfilesTest {

private static final String TABLE = "qprofiles";
private static final String TABLE = "org_qprofiles";

@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableQProfilesTest.class, "empty.sql");
public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableOrgQProfilesTest.class, "empty.sql");
@Rule
public ExpectedException expectedException = ExpectedException.none();

private CreateTableQProfiles underTest = new CreateTableQProfiles(db.database());
private CreateTableOrgQProfiles underTest = new CreateTableOrgQProfiles(db.database());

@Test
public void creates_table_on_empty_db() throws SQLException {
@@ -47,12 +47,13 @@ public class CreateTableQProfilesTest {
assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);

db.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
db.assertPrimaryKey(TABLE, "pk_qprofiles", "uuid");
db.assertPrimaryKey(TABLE, "pk_org_qprofiles", "uuid");
db.assertColumnDefinition(TABLE, "organization_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "rules_profile_uuid", Types.VARCHAR, 40, false);
db.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
db.assertColumnDefinition(TABLE, "updated_at", Types.BIGINT, null, false);
db.assertIndex(TABLE, "qprofiles_org_uuid", "organization_uuid");
db.assertIndex(TABLE, "qprofiles_rp_uuid", "rules_profile_uuid");
}

@Test

+ 1
- 1
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65Test.java 파일 보기

@@ -35,6 +35,6 @@ public class DbVersion65Test {

@Test
public void verify_migration_count() {
verifyMigrationCount(underTest, 24);
verifyMigrationCount(underTest, 25);
}
}

+ 43
- 0
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest.java 파일 보기

@@ -0,0 +1,43 @@
/*
* SonarQube
* Copyright (C) 2009-2017 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.server.platform.db.migration.version.v65;

import java.sql.SQLException;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.CoreDbTester;

public class DropOrgUuidAndParentKeeFromRulesProfilesTest {

private static final String TABLE_NAME = "rules_profiles";

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropOrgUuidAndParentKeeFromRulesProfilesTest.class, "initial.sql");

private DropOrgUuidAndParentKeeFromRulesProfiles underTest = new DropOrgUuidAndParentKeeFromRulesProfiles(db.database());

@Test
public void columns_are_dropped() throws SQLException {
underTest.execute();

db.assertColumnDoesNotExist(TABLE_NAME, "organization_uuid");
db.assertColumnDoesNotExist(TABLE_NAME, "parent_kee");
}
}

server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest.java → server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest.java 파일 보기

@@ -35,16 +35,16 @@ import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;


public class PopulateQProfilesTest {
public class PopulateOrgQProfilesTest {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateQProfilesTest.class, "initial.sql");
public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrgQProfilesTest.class, "initial.sql");

private System2 system2 = new AlwaysIncreasingSystem2();
private PopulateQProfiles underTest = new PopulateQProfiles(db.database(), system2);
private PopulateOrgQProfiles underTest = new PopulateOrgQProfiles(db.database(), system2);

@Test
public void migration_is_reentrant() throws SQLException {
@@ -52,13 +52,13 @@ public class PopulateQProfilesTest {
insertRulesProfile("ORG_2", "js", "u2", "u1", true);

// org1 is already processed
insertQProfile("u1", "ORG_1", "RPU1");
insertOrgQProfile("u1", "ORG_1", "RPU1");

underTest.execute();

assertThat(countRows()).isEqualTo(2);
Map<String, Object> qprofile1 = selectQProfile("u1", "ORG_1");
Map<String, Object> qprofile2 = selectQProfile("u2", "ORG_2");
Map<String, Object> qprofile1 = selectOrgQProfile("u1", "ORG_1");
Map<String, Object> qprofile2 = selectOrgQProfile("u2", "ORG_2");

assertThat(qprofile1.get("UUID")).isEqualTo("u1");
assertThat(qprofile1.get("ORGANIZATION_UUID")).isEqualTo("ORG_1");
@@ -86,7 +86,7 @@ public class PopulateQProfilesTest {


private int countRows() {
return db.countRowsOfTable("qprofiles");
return db.countRowsOfTable("org_qprofiles");
}

private void insertRulesProfile(String orgUuid, String language, String uuid, String parentKee, boolean isDefault) {
@@ -100,8 +100,8 @@ public class PopulateQProfilesTest {
"IS_BUILT_IN", true);
}

private void insertQProfile(String uuid, String orgUuid, String rulesProfileUuid) {
db.executeInsert("QPROFILES",
private void insertOrgQProfile(String uuid, String orgUuid, String rulesProfileUuid) {
db.executeInsert("ORG_QPROFILES",
"ORGANIZATION_UUID", orgUuid,
"RULES_PROFILE_UUID", rulesProfileUuid,
"UUID", uuid,
@@ -110,7 +110,7 @@ public class PopulateQProfilesTest {
);
}

private Map<String, Object> selectQProfile(String uuid, String orgUuid) {
return db.selectFirst(format("select * from qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid));
private Map<String, Object> selectOrgQProfile(String uuid, String orgUuid) {
return db.selectFirst(format("select * from org_qprofiles where uuid='%s' and organization_uuid='%s'", uuid, orgUuid));
}
}

server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableQProfilesTest/empty.sql → server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/CreateTableOrgQProfilesTest/empty.sql 파일 보기


+ 15
- 0
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/DropOrgUuidAndParentKeeFromRulesProfilesTest/initial.sql 파일 보기

@@ -0,0 +1,15 @@
CREATE TABLE "RULES_PROFILES" (
"ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
"NAME" VARCHAR(100) NOT NULL,
"LANGUAGE" VARCHAR(20),
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"KEE" VARCHAR(255) NOT NULL,
"PARENT_KEE" VARCHAR(255),
"RULES_UPDATED_AT" VARCHAR(100),
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
"LAST_USED" BIGINT,
"USER_UPDATED_AT" BIGINT,
"IS_BUILT_IN" BOOLEAN NOT NULL
);
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");

server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateQProfilesTest/initial.sql → server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v65/PopulateOrgQProfilesTest/initial.sql 파일 보기

@@ -15,7 +15,7 @@ CREATE TABLE "RULES_PROFILES" (
);
CREATE UNIQUE INDEX "UNIQ_QPROF_KEY" ON "RULES_PROFILES" ("KEE");

CREATE TABLE "QPROFILES" (
CREATE TABLE "ORG_QPROFILES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
"RULES_PROFILE_UUID" VARCHAR(40) NOT NULL,
@@ -23,4 +23,5 @@ CREATE TABLE "QPROFILES" (
"CREATED_AT" BIGINT NOT NULL,
"UPDATED_AT" BIGINT NOT NULL
);
CREATE INDEX "QPROFILES_ORG_UUID" ON "QPROFILES" ("ORGANIZATION_UUID");
CREATE INDEX "ORG_QPROFILES_ORG_UUID" ON "ORG_QPROFILES" ("ORGANIZATION_UUID");
CREATE INDEX "ORG_QPROFILES_RP_UUID" ON "ORG_QPROFILES" ("RULES_PROFILE_UUID");

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java 파일 보기

@@ -31,7 +31,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile;
import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
@@ -107,10 +107,10 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
.map(QProfile::getKey)
.collect(toList(metadata.getQprofilesPerLanguage().size()));
try (DbSession dbSession = dbClient.openSession(false)) {
List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectByKeys(dbSession, profileKeys);
List<QProfileDto> profiles = dbClient.qualityProfileDao().selectByUuids(dbSession, profileKeys);
String badKeys = profiles.stream()
.filter(p -> !p.getOrganizationUuid().equals(organization.getUuid()))
.map(RulesProfileDto::getKee)
.map(QProfileDto::getKee)
.collect(MoreCollectors.join(Joiner.on(", ")));
if (!badKeys.isEmpty()) {
throw MessageException.of(format("Quality profiles with following keys don't exist in organization [%s]: %s", organization.getKey(), badKeys));

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStep.java 파일 보기

@@ -26,7 +26,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
@@ -68,7 +68,7 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
return;
}

List<RulesProfileDto> dtos = dbClient.qualityProfileDao().selectByKeys(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
List<QProfileDto> dtos = dbClient.qualityProfileDao().selectByUuids(dbSession, qualityProfiles.stream().map(QualityProfile::getQpKey).collect(Collectors.toList()));
dtos.addAll(getAncestors(dbSession, dtos));
long analysisDate = analysisMetadataHolder.getAnalysisDate();
dtos.forEach(dto -> {
@@ -80,16 +80,16 @@ public class UpdateQualityProfilesLastUsedDateStep implements ComputationStep {
}
}

private List<RulesProfileDto> getAncestors(DbSession dbSession, List<RulesProfileDto> dtos) {
List<RulesProfileDto> ancestors = new ArrayList<>();
private List<QProfileDto> getAncestors(DbSession dbSession, List<QProfileDto> dtos) {
List<QProfileDto> ancestors = new ArrayList<>();
dtos.forEach(dto -> incrementAncestors(dbSession, dto, ancestors));
return ancestors;
}

private void incrementAncestors(DbSession session, RulesProfileDto profile, List<RulesProfileDto> ancestors) {
private void incrementAncestors(DbSession session, QProfileDto profile, List<QProfileDto> ancestors) {
String parentKey = profile.getParentKee();
if (parentKey != null) {
RulesProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByKey(session, parentKey);
QProfileDto parentDto = dbClient.qualityProfileDao().selectOrFailByUuid(session, parentKey);
ancestors.add(parentDto);
incrementAncestors(session, parentDto, ancestors);
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/organization/ws/DeleteAction.java 파일 보기

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.organization.DefaultOrganization;
import org.sonar.server.organization.DefaultOrganizationProvider;
@@ -134,9 +134,9 @@ public class DeleteAction implements OrganizationsWsAction {
}

private void deleteQualityProfiles(DbSession dbSession, OrganizationDto organization) {
List<RulesProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
List<QProfileDto> profiles = dbClient.qualityProfileDao().selectAll(dbSession, organization);
List<String> profileKeys = profiles.stream()
.map(RulesProfileDto::getKee)
.map(QProfileDto::getKee)
.collect(MoreCollectors.toArrayList(profiles.size()));
qProfileFactory.deleteByKeys(dbSession, profileKeys);
dbSession.commit();

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/BuiltInQProfileInsertImpl.java 파일 보기

@@ -47,7 +47,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.util.TypeValidations;
@@ -75,7 +75,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
initRuleRepository(batchSession);

Date now = new Date(system2.now());
RulesProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);
QProfileDto profileDto = insertQualityProfile(session, builtInQProfile, organization, now);

List<ActiveRuleChange> localChanges = builtInQProfile.getActiveRules()
.stream()
@@ -91,8 +91,8 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
}
}

private RulesProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
RulesProfileDto profileDto = RulesProfileDto.createFor(uuidFactory.create())
private QProfileDto insertQualityProfile(DbSession dbSession, BuiltInQProfile builtInQProfile, OrganizationDto organization, Date now) {
QProfileDto profileDto = QProfileDto.createFor(uuidFactory.create())
.setName(builtInQProfile.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(builtInQProfile.getLanguage())
@@ -105,7 +105,7 @@ public class BuiltInQProfileInsertImpl implements BuiltInQProfileInsert {
return profileDto;
}

private ActiveRuleChange insertActiveRule(DbSession session, RulesProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
private ActiveRuleChange insertActiveRule(DbSession session, QProfileDto profileDto, org.sonar.api.rules.ActiveRule activeRule, long now) {
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey());
RuleDefinitionDto ruleDefinitionDto = ruleRepository.getDefinition(ruleKey)
.orElseThrow(() -> new IllegalStateException("RuleDefinition not found for key " + ruleKey));

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuper.java 파일 보기

@@ -24,14 +24,14 @@ import java.io.Writer;
import javax.annotation.Nullable;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

/**
* Backup and restore a Quality profile.
*/
public interface QProfileBackuper {

void backup(DbSession dbSession, RulesProfileDto profile, Writer backupWriter);
void backup(DbSession dbSession, QProfileDto profile, Writer backupWriter);

/**
* Restore backup on a profile in the specified organization. The parameter {@code overriddenProfileName}
@@ -43,5 +43,5 @@ public interface QProfileBackuper {
/**
* Restore backup on an existing profile.
*/
QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile);
QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile);
}

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileBackuperImpl.java 파일 보기

@@ -47,7 +47,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static com.google.common.base.Preconditions.checkArgument;

@@ -82,13 +82,13 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

@Override
public void backup(DbSession dbSession, RulesProfileDto profileDto, Writer writer) {
public void backup(DbSession dbSession, QProfileDto profileDto, Writer writer) {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profileDto.getKee());
activeRules.sort(BackupActiveRuleComparator.INSTANCE);
writeXml(dbSession, writer, profileDto, activeRules.iterator());
}

private void writeXml(DbSession dbSession, Writer writer, RulesProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
private void writeXml(DbSession dbSession, Writer writer, QProfileDto profile, Iterator<ActiveRuleDto> activeRules) {
XmlWriter xml = XmlWriter.of(writer).declaration();
xml.begin(ATTRIBUTE_PROFILE);
xml.prop(ATTRIBUTE_NAME, profile.getName());
@@ -126,7 +126,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

@Override
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, RulesProfileDto profile) {
public QProfileRestoreSummary restore(DbSession dbSession, Reader backup, QProfileDto profile) {
return restore(dbSession, backup, nameInBackup -> {
checkArgument(profile.getLanguage().equals(nameInBackup.getLanguage()),
"Can't restore %s backup on %s profile with key [%s]. Languages are different.", nameInBackup.getLanguage(), profile.getLanguage(), profile.getKee());
@@ -134,7 +134,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
});
}

private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, RulesProfileDto> profileLoader) {
private QProfileRestoreSummary restore(DbSession dbSession, Reader backup, Function<QProfileName, QProfileDto> profileLoader) {
try {
String profileLang = null;
String profileName = null;
@@ -161,7 +161,7 @@ public class QProfileBackuperImpl implements QProfileBackuper {
}

QProfileName targetName = new QProfileName(profileLang, profileName);
RulesProfileDto targetProfile = profileLoader.apply(targetName);
QProfileDto targetProfile = profileLoader.apply(targetName);
BulkChangeResult changes = profileReset.reset(dbSession, targetProfile, ruleActivations);
return new QProfileRestoreSummary(targetProfile, changes);
} catch (XMLStreamException e) {

+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileComparison.java 파일 보기

@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

@ServerSide
@ComputeEngineSide
@@ -48,7 +48,7 @@ public class QProfileComparison {
this.dbClient = dbClient;
}

public QProfileComparisonResult compare(DbSession dbSession, RulesProfileDto left, RulesProfileDto right) {
public QProfileComparisonResult compare(DbSession dbSession, QProfileDto left, QProfileDto right) {
Map<RuleKey, ActiveRuleDto> leftActiveRulesByRuleKey = loadActiveRules(dbSession, left);
Map<RuleKey, ActiveRuleDto> rightActiveRulesByRuleKey = loadActiveRules(dbSession, right);

@@ -86,29 +86,29 @@ public class QProfileComparison {
}
}

private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, RulesProfileDto profile) {
private Map<RuleKey, ActiveRuleDto> loadActiveRules(DbSession session, QProfileDto profile) {
return Maps.uniqueIndex(dbClient.activeRuleDao().selectByProfileKey(session, profile.getKee()), ActiveRuleToRuleKey.INSTANCE);
}

public static class QProfileComparisonResult {

private final RulesProfileDto left;
private final RulesProfileDto right;
private final QProfileDto left;
private final QProfileDto right;
private final Map<RuleKey, ActiveRuleDto> inLeft = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> inRight = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDiff> modified = Maps.newHashMap();
private final Map<RuleKey, ActiveRuleDto> same = Maps.newHashMap();

public QProfileComparisonResult(RulesProfileDto left, RulesProfileDto right) {
public QProfileComparisonResult(QProfileDto left, QProfileDto right) {
this.left = left;
this.right = right;
}

public RulesProfileDto left() {
public QProfileDto left() {
return left;
}

public RulesProfileDto right() {
public QProfileDto right() {
return right;
}


+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.api.utils.TempFolder;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static java.nio.charset.StandardCharsets.UTF_8;

@@ -51,10 +51,10 @@ public class QProfileCopier {
this.temp = temp;
}

public RulesProfileDto copyToName(DbSession dbSession, RulesProfileDto sourceProfile, String toName) {
public QProfileDto copyToName(DbSession dbSession, QProfileDto sourceProfile, String toName) {
OrganizationDto organization = db.organizationDao().selectByUuid(dbSession, sourceProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException("Organization with UUID [" + sourceProfile.getOrganizationUuid() + "] does not exist"));
RulesProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
QProfileDto to = prepareTarget(dbSession, organization, sourceProfile, toName);
File backupFile = temp.newFile();
try {
backup(dbSession, sourceProfile, backupFile);
@@ -65,10 +65,10 @@ public class QProfileCopier {
}
}

private RulesProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, RulesProfileDto sourceProfile, String toName) {
private QProfileDto prepareTarget(DbSession dbSession, OrganizationDto organization, QProfileDto sourceProfile, String toName) {
QProfileName toProfileName = new QProfileName(sourceProfile.getLanguage(), toName);
verify(sourceProfile, toProfileName);
RulesProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(organization, toProfileName.getName(), toProfileName.getLanguage(), dbSession);
QProfileDto toProfile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, toProfileName.getName(), toProfileName.getLanguage());
if (toProfile == null) {
toProfile = factory.checkAndCreateCustom(dbSession, organization, toProfileName);
toProfile.setParentKee(sourceProfile.getParentKee());
@@ -78,7 +78,7 @@ public class QProfileCopier {
return toProfile;
}

private void verify(RulesProfileDto fromProfile, QProfileName toProfileName) {
private void verify(QProfileDto fromProfile, QProfileName toProfileName) {
if (!StringUtils.equals(fromProfile.getLanguage(), toProfileName.getLanguage())) {
throw new IllegalArgumentException(String.format(
"Source and target profiles do not have the same language: %s and %s",
@@ -90,7 +90,7 @@ public class QProfileCopier {
}
}

private void backup(DbSession dbSession, RulesProfileDto profile, File backupFile) {
private void backup(DbSession dbSession, QProfileDto profile, File backupFile) {
try (Writer writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), UTF_8)) {
backuper.backup(dbSession, profile, writer);
} catch (IOException e) {
@@ -98,7 +98,7 @@ public class QProfileCopier {
}
}

private void restore(DbSession dbSession, File backupFile, RulesProfileDto profile) {
private void restore(DbSession dbSession, File backupFile, QProfileDto profile) {
try (Reader reader = new InputStreamReader(FileUtils.openInputStream(backupFile), UTF_8)) {
backuper.restore(dbSession, reader, profile);
} catch (IOException e) {

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java 파일 보기

@@ -44,7 +44,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.NotFoundException;

@@ -103,12 +103,12 @@ public class QProfileExporters {
return exporter.getMimeType();
}

public void export(RulesProfileDto profile, String exporterKey, Writer writer) {
public void export(QProfileDto profile, String exporterKey, Writer writer) {
ProfileExporter exporter = findExporter(exporterKey);
exporter.exportProfile(wrap(profile), writer);
}

private RulesProfile wrap(RulesProfileDto profile) {
private RulesProfile wrap(QProfileDto profile) {
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfile target = new RulesProfile(profile.getName(), profile.getLanguage());
List<ActiveRuleDto> activeRuleDtos = dbClient.activeRuleDao().selectByProfileKey(dbSession, profile.getKee());
@@ -137,11 +137,11 @@ public class QProfileExporters {
throw new NotFoundException("Unknown quality profile exporter: " + exporterKey);
}

public QProfileResult importXml(RulesProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
public QProfileResult importXml(QProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) {
return importXml(profileDto, importerKey, new InputStreamReader(xml, StandardCharsets.UTF_8), dbSession);
}

private QProfileResult importXml(RulesProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
private QProfileResult importXml(QProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) {
QProfileResult result = new QProfileResult();
ValidationMessages messages = ValidationMessages.create();
ProfileImporter importer = getProfileImporter(importerKey);
@@ -152,7 +152,7 @@ public class QProfileExporters {
return result;
}

private List<ActiveRuleChange> importProfile(RulesProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
private List<ActiveRuleChange> importProfile(QProfileDto profileDto, RulesProfile rulesProfile, DbSession dbSession) {
List<ActiveRuleChange> changes = new ArrayList<>();
for (org.sonar.api.rules.ActiveRule activeRule : rulesProfile.getActiveRules()) {
changes.addAll(ruleActivator.activate(dbSession, toRuleActivation(activeRule), profileDto));

+ 17
- 17
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;

@@ -61,9 +61,9 @@ public class QProfileFactory {
return organization;
}

RulesProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
QProfileDto getOrCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name.getName(), name.getLanguage());
if (profile == null) {
profile = doCreate(dbSession, organization, name, false, false);
} else {
@@ -78,9 +78,9 @@ public class QProfileFactory {
*
* @throws BadRequestException if a quality profile with the specified name already exists
*/
public RulesProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
public QProfileDto checkAndCreateCustom(DbSession dbSession, OrganizationDto organization, QProfileName name) {
requireNonNull(organization);
RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, name.getName(), name.getLanguage(), dbSession);
QProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name.getName(), name.getLanguage());
checkRequest(dto == null, "Quality profile already exists: %s", name);
return doCreate(dbSession, organization, name, false, false);
}
@@ -90,16 +90,16 @@ public class QProfileFactory {
*
* A DB error will be thrown if the quality profile already exists.
*/
public RulesProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
public QProfileDto createBuiltIn(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault) {
return doCreate(dbSession, requireNonNull(organization), name, isDefault, true);
}

private RulesProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
private QProfileDto doCreate(DbSession dbSession, OrganizationDto organization, QProfileName name, boolean isDefault, boolean isBuiltIn) {
if (StringUtils.isEmpty(name.getName())) {
throw BadRequestException.create("quality_profiles.profile_name_cant_be_blank");
}
Date now = new Date(system2.now());
RulesProfileDto dto = RulesProfileDto.createFor(uuidFactory.create())
QProfileDto dto = QProfileDto.createFor(uuidFactory.create())
.setName(name.getName())
.setOrganizationUuid(organization.getUuid())
.setLanguage(name.getLanguage())
@@ -120,16 +120,16 @@ public class QProfileFactory {
* are deleted too. Deleting a parent profile does not delete descendants
* if their keys are not listed.
*/
public void deleteByKeys(DbSession dbSession, Collection<String> profileKeys) {
if (!profileKeys.isEmpty()) {
db.qualityProfileDao().deleteProjectAssociationsByProfileKeys(dbSession, profileKeys);
db.activeRuleDao().deleteParametersByProfileKeys(dbSession, profileKeys);
db.activeRuleDao().deleteByProfileKeys(dbSession, profileKeys);
db.qProfileChangeDao().deleteByProfileKeys(dbSession, profileKeys);
db.defaultQProfileDao().deleteByQProfileUuids(dbSession, profileKeys);
db.qualityProfileDao().deleteByKeys(dbSession, profileKeys);
public void deleteByKeys(DbSession dbSession, Collection<String> profileUuids) {
if (!profileUuids.isEmpty()) {
db.qualityProfileDao().deleteProjectAssociationsByProfileUuids(dbSession, profileUuids);
db.activeRuleDao().deleteParametersByProfileKeys(dbSession, profileUuids);
db.activeRuleDao().deleteByProfileKeys(dbSession, profileUuids);
db.qProfileChangeDao().deleteByProfileKeys(dbSession, profileUuids);
db.defaultQProfileDao().deleteByQProfileUuids(dbSession, profileUuids);
db.qualityProfileDao().deleteByUuids(dbSession, profileUuids);
dbSession.commit();
activeRuleIndexer.deleteByProfileKeys(profileKeys);
activeRuleIndexer.deleteByProfileKeys(profileUuids);
}
}


+ 8
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileLookup.java 파일 보기

@@ -19,12 +19,13 @@
*/
package org.sonar.server.qualityprofile;

import java.util.Collection;
import java.util.List;
import org.sonar.api.server.ServerSide;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static com.google.common.collect.Lists.newArrayList;

@@ -37,23 +38,23 @@ public class QProfileLookup {
this.db = db;
}

public List<RulesProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
public List<QProfileDto> allProfiles(DbSession dbSession, OrganizationDto organization) {
return db.qualityProfileDao().selectAll(dbSession, organization);
}

public List<RulesProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
public Collection<QProfileDto> profiles(DbSession dbSession, String language, OrganizationDto organization) {
return db.qualityProfileDao().selectByLanguage(dbSession, organization, language);
}

public List<RulesProfileDto> ancestors(RulesProfileDto profile, DbSession session) {
List<RulesProfileDto> ancestors = newArrayList();
public List<QProfileDto> ancestors(QProfileDto profile, DbSession session) {
List<QProfileDto> ancestors = newArrayList();
incrementAncestors(profile, ancestors, session);
return ancestors;
}

private void incrementAncestors(RulesProfileDto profile, List<RulesProfileDto> ancestors, DbSession session) {
private void incrementAncestors(QProfileDto profile, List<QProfileDto> ancestors, DbSession session) {
if (profile.getParentKee() != null) {
RulesProfileDto parentDto = db.qualityProfileDao().selectByKey(session, profile.getParentKee());
QProfileDto parentDto = db.qualityProfileDao().selectByUuid(session, profile.getParentKee());
if (parentDto == null) {
throw new IllegalStateException("Cannot find parent of profile : " + profile.getId());
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileReset.java 파일 보기

@@ -21,12 +21,12 @@ package org.sonar.server.qualityprofile;

import java.util.Collection;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

public interface QProfileReset {

/**
* Reset the rules of the specified profile.
*/
BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations);
BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations);
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResetImpl.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;

@@ -51,7 +51,7 @@ public class QProfileResetImpl implements QProfileReset {
}

@Override
public BulkChangeResult reset(DbSession dbSession, RulesProfileDto profile, Collection<RuleActivation> activations) {
public BulkChangeResult reset(DbSession dbSession, QProfileDto profile, Collection<RuleActivation> activations) {
requireNonNull(profile.getId(), "Quality profile must be persisted");
checkArgument(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s'", profile.getKee());
BulkChangeResult result = new BulkChangeResult();

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileRestoreSummary.java 파일 보기

@@ -19,20 +19,20 @@
*/
package org.sonar.server.qualityprofile;

import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static java.util.Objects.requireNonNull;

public final class QProfileRestoreSummary {
private final RulesProfileDto profile;
private final QProfileDto profile;
private final BulkChangeResult ruleChanges;

public QProfileRestoreSummary(RulesProfileDto profile, BulkChangeResult ruleChanges) {
public QProfileRestoreSummary(QProfileDto profile, BulkChangeResult ruleChanges) {
this.profile = requireNonNull(profile);
this.ruleChanges = requireNonNull(ruleChanges);
}

public RulesProfileDto getProfile() {
public QProfileDto getProfile() {
return profile;
}


+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileResult.java 파일 보기

@@ -21,14 +21,14 @@ package org.sonar.server.qualityprofile;

import java.util.ArrayList;
import java.util.List;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

public class QProfileResult {

private List<String> warnings;
private List<String> infos;

private RulesProfileDto profile;
private QProfileDto profile;

private List<ActiveRuleChange> changes;

@@ -56,11 +56,11 @@ public class QProfileResult {
return this;
}

public RulesProfileDto profile() {
public QProfileDto profile() {
return profile;
}

public QProfileResult setProfile(RulesProfileDto profile) {
public QProfileResult setProfile(QProfileDto profile) {
this.profile = profile;
return this;
}

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RegisterQualityProfiles.java 파일 보기

@@ -104,12 +104,12 @@ public class RegisterQualityProfiles {
* built-in profile "Sonar way", which has probably different configuration.
*/
private void renameOutdatedProfiles(DbSession dbSession, BuiltInQProfile profile) {
Collection<String> profileKeys = dbClient.qualityProfileDao().selectOutdatedProfiles(dbSession, profile.getLanguage(), profile.getName());
if (profileKeys.isEmpty()) {
Collection<String> uuids = dbClient.qualityProfileDao().selectUuidsOfCustomRulesProfiles(dbSession, profile.getLanguage(), profile.getName());
if (uuids.isEmpty()) {
return;
}
String newName = profile.getName() + " (outdated copy)";
LOGGER.info("Rename Quality profiles [{}/{}] to [{}] in {} organizations", profile.getLanguage(), profile.getName(), newName, profileKeys.size());
dbClient.qualityProfileDao().renameAndCommit(dbSession, profileKeys, newName);
LOGGER.info("Rename Quality profiles [{}/{}] to [{}] in {} organizations", profile.getLanguage(), profile.getName(), newName, uuids.size());
dbClient.qualityProfileDao().renameRulesProfilesAndCommit(dbSession, uuids, newName);
}
}

+ 16
- 16
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivator.java 파일 보기

@@ -38,7 +38,7 @@ import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.exceptions.BadRequestException;
@@ -82,7 +82,7 @@ public class RuleActivator {
return doActivate(dbSession, activation, context);
}

public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, RulesProfileDto profileDto) {
public List<ActiveRuleChange> activate(DbSession dbSession, RuleActivation activation, QProfileDto profileDto) {
RuleActivatorContext context = contextFactory.create(profileDto, activation.getRuleKey(), dbSession);
return doActivate(dbSession, activation, context);
}
@@ -146,7 +146,7 @@ public class RuleActivator {
}

private void updateProfileDates(DbSession dbSession, RuleActivatorContext context) {
RulesProfileDto profile = context.profile();
QProfileDto profile = context.profile();
profile.setRulesUpdatedAtAsDate(context.getInitDate());
if (userSession.isLoggedIn()) {
profile.setUserUpdatedAt(context.getInitDate().getTime());
@@ -224,20 +224,20 @@ public class RuleActivator {
return null;
}

private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, RulesProfileDto rulesProfileDto) {
private List<ActiveRuleChange> cascadeActivation(DbSession session, RuleActivation activation, QProfileDto qProfileDto) {
List<ActiveRuleChange> changes = Lists.newArrayList();

// get all inherited profiles
String qualityProfileKey = rulesProfileDto.getKee();
List<RulesProfileDto> children = getChildren(session, qualityProfileKey);
for (RulesProfileDto child : children) {
String qualityProfileKey = qProfileDto.getKee();
List<QProfileDto> children = getChildren(session, qualityProfileKey);
for (QProfileDto child : children) {
RuleActivation childActivation = new RuleActivation(activation).setCascade(true);
changes.addAll(activate(session, childActivation, child));
}
return changes;
}

protected List<RulesProfileDto> getChildren(DbSession session, String qualityProfileKey) {
protected List<QProfileDto> getChildren(DbSession session, String qualityProfileKey) {
return db.qualityProfileDao().selectChildren(session, qualityProfileKey);
}

@@ -370,9 +370,9 @@ public class RuleActivator {
persist(change, context, dbSession);

// get all inherited profiles
List<RulesProfileDto> profiles = getChildren(dbSession, key.qProfile());
List<QProfileDto> profiles = getChildren(dbSession, key.qProfile());

for (RulesProfileDto profile : profiles) {
for (QProfileDto profile : profiles) {
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKee(), key.ruleKey());
changes.addAll(cascadeDeactivation(activeRuleKey, dbSession, true, force));
}
@@ -457,14 +457,14 @@ public class RuleActivator {
}

public List<ActiveRuleChange> setParent(DbSession dbSession, String profileKey, @Nullable String parentKey) {
RulesProfileDto profile = db.qualityProfileDao().selectOrFailByKey(dbSession, profileKey);
QProfileDto profile = db.qualityProfileDao().selectOrFailByUuid(dbSession, profileKey);
List<ActiveRuleChange> changes = new ArrayList<>();
if (parentKey == null) {
// unset if parent is defined, else nothing to do
changes.addAll(removeParent(dbSession, profile));

} else if (profile.getParentKee() == null || !parentKey.equals(profile.getParentKee())) {
RulesProfileDto parentProfile = db.qualityProfileDao().selectOrFailByKey(dbSession, parentKey);
QProfileDto parentProfile = db.qualityProfileDao().selectOrFailByUuid(dbSession, parentKey);
checkRequest(!isDescendant(dbSession, profile, parentProfile), "Descendant profile '%s' can not be selected as parent of '%s'", parentKey, profileKey);
changes.addAll(removeParent(dbSession, profile));

@@ -489,7 +489,7 @@ public class RuleActivator {
/**
* Does not commit
*/
private List<ActiveRuleChange> removeParent(DbSession dbSession, RulesProfileDto profileDto) {
private List<ActiveRuleChange> removeParent(DbSession dbSession, QProfileDto profileDto) {
if (profileDto.getParentKee() != null) {
List<ActiveRuleChange> changes = new ArrayList<>();
profileDto.setParentKee(null);
@@ -509,15 +509,15 @@ public class RuleActivator {
return Collections.emptyList();
}

boolean isDescendant(DbSession dbSession, RulesProfileDto childProfile, @Nullable RulesProfileDto parentProfile) {
RulesProfileDto currentParent = parentProfile;
boolean isDescendant(DbSession dbSession, QProfileDto childProfile, @Nullable QProfileDto parentProfile) {
QProfileDto currentParent = parentProfile;
while (currentParent != null) {
if (childProfile.getName().equals(currentParent.getName())) {
return true;
}
String parentKey = currentParent.getParentKee();
if (parentKey != null) {
currentParent = db.qualityProfileDao().selectByKey(dbSession, parentKey);
currentParent = db.qualityProfileDao().selectByUuid(dbSession, parentKey);
} else {
currentParent = null;
}

+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContext.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.api.rule.RuleStatus;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;

@@ -41,7 +41,7 @@ class RuleActivatorContext {
private final Date initDate = new Date();
private RuleDefinitionDto rule;
private final Map<String, RuleParamDto> ruleParams = Maps.newHashMap();
private RulesProfileDto profile;
private QProfileDto profile;
private ActiveRuleDto activeRule;
private ActiveRuleDto parentActiveRule;
private final Map<String, ActiveRuleParamDto> activeRuleParams = Maps.newHashMap();
@@ -83,11 +83,11 @@ class RuleActivatorContext {
return this;
}

RulesProfileDto profile() {
QProfileDto profile() {
return profile;
}

RuleActivatorContext setProfile(RulesProfileDto profile) {
RuleActivatorContext setProfile(QProfileDto profile) {
this.profile = profile;
return this;
}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleParamDto;

@@ -46,13 +46,13 @@ public class RuleActivatorContextFactory {

RuleActivatorContext create(String profileKey, RuleKey ruleKey, DbSession session) {
RuleActivatorContext context = new RuleActivatorContext();
RulesProfileDto profile = getQualityProfileDto(session, profileKey);
QProfileDto profile = getQualityProfileDto(session, profileKey);
checkRequest(profile != null, "Quality profile not found: %s", profileKey);
context.setProfile(profile);
return create(ruleKey, session, context);
}

RuleActivatorContext create(RulesProfileDto profile, RuleKey ruleKey, DbSession session) {
RuleActivatorContext create(QProfileDto profile, RuleKey ruleKey, DbSession session) {
return create(ruleKey, session, new RuleActivatorContext().setProfile(profile));
}

@@ -91,8 +91,8 @@ public class RuleActivatorContextFactory {
}
}

RulesProfileDto getQualityProfileDto(DbSession session, String profileKey) {
return db.qualityProfileDao().selectByKey(session, profileKey);
QProfileDto getQualityProfileDto(DbSession session, String profileKey) {
return db.qualityProfileDao().selectByUuid(session, profileKey);
}

Optional<RuleDefinitionDto> getRule(DbSession dbSession, RuleKey ruleKey) {

+ 1
- 11
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleDoc.java 파일 보기

@@ -27,10 +27,9 @@ import org.sonar.server.qualityprofile.ActiveRule;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ORGANIZATION_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_CREATED_AT;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_INHERITANCE;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_ORGANIZATION_UUID;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_PROFILE_KEY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_REPOSITORY;
import static org.sonar.server.rule.index.RuleIndexDefinition.FIELD_ACTIVE_RULE_RULE_KEY;
@@ -107,15 +106,6 @@ public class ActiveRuleDoc extends BaseDoc {
return this;
}

long createdAt() {
return (Long) getField(FIELD_ACTIVE_RULE_CREATED_AT);
}

public ActiveRuleDoc setCreatedAt(@Nullable Long l) {
setField(FIELD_ACTIVE_RULE_CREATED_AT, l);
return this;
}

long updatedAt() {
return (Long) getField(FIELD_ACTIVE_RULE_UPDATED_AT);
}

+ 11
- 12
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleResultSetIterator.java 파일 보기

@@ -37,21 +37,21 @@ import org.sonar.server.qualityprofile.ActiveRule;
public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc> {

private static final String[] FIELDS = {
"a.failure_level",
"a.inheritance",
"ar.failure_level",
"ar.inheritance",
"r.plugin_name",
"r.plugin_rule_key",
"qp.organization_uuid",
"qp.kee",
"a.created_at",
"a.updated_at"
"oqp.organization_uuid",
"oqp.uuid",
"ar.updated_at"
};

private static final String SQL_ALL = "SELECT " + StringUtils.join(FIELDS, ",") + " FROM active_rules a " +
"INNER JOIN rules_profiles qp ON qp.id=a.profile_id " +
"INNER JOIN rules r ON r.id = a.rule_id";
private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from active_rules ar " +
" inner join rules_profiles rp on rp.id = ar.profile_id " +
" inner join org_qprofiles oqp on oqp.uuid = rp.kee " +
" inner join rules r on r.id = ar.rule_id ";

private static final String SQL_AFTER_DATE = SQL_ALL + " WHERE a.updated_at>?";
private static final String SQL_AFTER_DATE = SQL_ALL + " where ar.updated_at>?";

private ActiveRuleResultSetIterator(PreparedStatement stmt) throws SQLException {
super(stmt);
@@ -86,8 +86,7 @@ public class ActiveRuleResultSetIterator extends ResultSetIterator<ActiveRuleDoc

doc.setInheritance(inheritance == null ? ActiveRule.Inheritance.NONE.name() : inheritance);

doc.setCreatedAt(rs.getLong(7));
doc.setUpdatedAt(rs.getLong(8));
doc.setUpdatedAt(rs.getLong(7));
return doc;
}


+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRuleAction.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.ActiveRuleChange;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
@@ -107,7 +107,7 @@ public class ActivateRuleAction implements QProfileWsAction {
String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileKey);

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ActivateRulesAction.java 파일 보기

@@ -26,7 +26,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.ws.RuleQueryFactory;
@@ -83,7 +83,7 @@ public class ActivateRulesAction implements QProfileWsAction {
userSession.checkLoggedIn();
BulkChangeResult result;
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, fromKey(qualityProfileKey));
QProfileDto profile = wsSupport.getProfile(dbSession, fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
result = ruleActivator.bulkActivate(ruleQueryFactory.createRuleQuery(dbSession, request), qualityProfileKey, request.param(SEVERITY));

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/AddProjectAction.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -81,13 +81,13 @@ public class AddProjectAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));

if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");
}

RulesProfileDto currentProfile = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage());
QProfileDto currentProfile = dbClient.qualityProfileDao().selectAssociatedToProjectAndLanguage(dbSession, project, profile.getLanguage());
if (currentProfile == null) {
// project uses the default profile
dbClient.qualityProfileDao().insertProjectProfileAssociation(dbSession, project, profile);

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/BackupAction.java 파일 보기

@@ -28,7 +28,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonarqube.ws.MediaTypes;

@@ -69,7 +69,7 @@ public class BackupAction implements QProfileWsAction {
try (OutputStreamWriter writer = new OutputStreamWriter(stream.output(), UTF_8);
DbSession dbSession = dbClient.openSession(false)) {

RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
response.setHeader("Content-Disposition", String.format("attachment; filename=%s.xml", profile.getKee()));
backuper.backup(dbSession, profile, writer);
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangeParentAction.java 파일 보기

@@ -28,7 +28,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;

@@ -85,7 +85,7 @@ public class ChangeParentAction implements QProfileWsAction {
QProfileReference reference = QProfileReference.from(request);

try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
QProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' of profile '%s'", organizationUuid, profile.getKee())));
@@ -100,7 +100,7 @@ public class ChangeParentAction implements QProfileWsAction {
String parentOrganizationKey = parentKey == null ? organization.getKey() : null;
String parentLanguage = parentKey == null ? request.param(PARAM_LANGUAGE) : null;
QProfileReference parentRef = QProfileReference.from(parentKey, parentOrganizationKey, parentLanguage, parentName);
RulesProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
QProfileDto parent = wsSupport.getProfile(dbSession, parentRef);
ruleActivator.setParent(dbSession, profile.getKee(), parent.getKee());
}
response.noContent();

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.QProfileChangeQuery;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
@@ -84,7 +84,7 @@ public class ChangelogAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
QProfileDto profile = wsSupport.getProfile(dbSession, reference);

QProfileChangeQuery query = new QProfileChangeQuery(profile.getKee());
Date since = parseStartingDateOrDateTime(request.param(PARAM_SINCE));

+ 1
- 1
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogLoader.java 파일 보기

@@ -58,7 +58,7 @@ public class ChangelogLoader {
.collect(MoreCollectors.toList(dtos.size()));
completeUserAndRuleNames(dbSession, changes);

int total = dbClient.qProfileChangeDao().countForProfileKey(dbSession, query.getProfileKey());
int total = dbClient.qProfileChangeDao().countForProfileUuid(dbSession, query.getProfileUuid());
return new Changelog(total, changes);
}


+ 4
- 4
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CompareAction.java 파일 보기

@@ -39,7 +39,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleRepositoryDto;
import org.sonar.server.qualityprofile.QProfileComparison;
@@ -104,9 +104,9 @@ public class CompareAction implements QProfileWsAction {
String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);

try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto left = dbClient.qualityProfileDao().selectByKey(dbSession, leftKey);
QProfileDto left = dbClient.qualityProfileDao().selectByUuid(dbSession, leftKey);
checkArgument(left != null, "Could not find left profile '%s'", leftKey);
RulesProfileDto right = dbClient.qualityProfileDao().selectByKey(dbSession, rightKey);
QProfileDto right = dbClient.qualityProfileDao().selectByUuid(dbSession, rightKey);
checkArgument(right != null, "Could not find right profile '%s'", rightKey);

checkArgument(Objects.equals(left.getOrganizationUuid(), right.getOrganizationUuid()),
@@ -148,7 +148,7 @@ public class CompareAction implements QProfileWsAction {
json.endObject().close();
}

private void writeProfile(JsonWriter json, RulesProfileDto profile) {
private void writeProfile(JsonWriter json, QProfileDto profile) {
json.prop(ATTRIBUTE_KEY, profile.getKee())
.prop(ATTRIBUTE_NAME, profile.getName());
}

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileCopier;
import org.sonar.server.user.UserSession;

@@ -79,10 +79,10 @@ public class CopyAction implements QProfileWsAction {
String profileKey = request.mandatoryParam(PARAM_PROFILE_KEY);

try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
QProfileDto sourceProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, sourceProfile.getOrganizationUuid());

RulesProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
QProfileDto copiedProfile = profileCopier.copyToName(dbSession, sourceProfile, newName);
boolean isDefault = dbClient.defaultQProfileDao().isDefault(dbSession, copiedProfile.getOrganizationUuid(), copiedProfile.getKee());

String languageKey = copiedProfile.getLanguage();

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CreateAction.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileName;
@@ -123,7 +123,7 @@ public class CreateAction implements QProfileWsAction {

private CreateWsResponse doHandle(DbSession dbSession, CreateRequest createRequest, Request request, OrganizationDto organization) {
QProfileResult result = new QProfileResult();
RulesProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
QProfileDto profile = profileFactory.checkAndCreateCustom(dbSession, organization,
QProfileName.createFor(createRequest.getLanguage(), createRequest.getProfileName()));
result.setProfile(profile);
for (ProfileImporter importer : importers) {

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRuleAction.java 파일 보기

@@ -28,7 +28,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.user.UserSession;

@@ -76,7 +76,7 @@ public class DeactivateRuleAction implements QProfileWsAction {
String qualityProfileKey = request.mandatoryParam(PARAM_PROFILE_KEY);
userSession.checkLoggedIn();
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(qualityProfileKey, ruleKey);

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeactivateRulesAction.java 파일 보기

@@ -25,7 +25,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.rule.ws.RuleQueryFactory;
@@ -77,7 +77,7 @@ public class DeactivateRulesAction implements QProfileWsAction {
userSession.checkLoggedIn();
BulkChangeResult result;
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(qualityProfileKey));
wsSupport.checkPermission(dbSession, profile);
wsSupport.checkNotBuiltInt(profile);
result = ruleActivator.bulkDeactivate(ruleQueryFactory.createRuleQuery(dbSession, request), qualityProfileKey);

+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/DeleteAction.java 파일 보기

@@ -31,7 +31,7 @@ import org.sonar.api.server.ws.WebService.NewController;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.user.UserSession;

@@ -72,11 +72,11 @@ public class DeleteAction implements QProfileWsAction {
userSession.checkLoggedIn();

try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, profile.getOrganizationUuid());
wsSupport.checkNotBuiltInt(profile);

List<RulesProfileDto> descendants = selectDescendants(dbSession, profile);
List<QProfileDto> descendants = selectDescendants(dbSession, profile);
ensureNoneIsMarkedAsDefault(dbSession, profile, descendants);

profileFactory.deleteByKeys(dbSession, toKeys(profile, descendants));
@@ -85,11 +85,11 @@ public class DeleteAction implements QProfileWsAction {
response.noContent();
}

private List<RulesProfileDto> selectDescendants(DbSession dbSession, RulesProfileDto profile) {
private List<QProfileDto> selectDescendants(DbSession dbSession, QProfileDto profile) {
return dbClient.qualityProfileDao().selectDescendants(dbSession, profile.getKee());
}

private void ensureNoneIsMarkedAsDefault(DbSession dbSession, RulesProfileDto profile, List<RulesProfileDto> descendants) {
private void ensureNoneIsMarkedAsDefault(DbSession dbSession, QProfileDto profile, List<QProfileDto> descendants) {
Set<String> allUuids = new HashSet<>();
allUuids.add(profile.getKee());
descendants.forEach(p -> allUuids.add(p.getKee()));
@@ -105,9 +105,9 @@ public class DeleteAction implements QProfileWsAction {
});
}

private static List<String> toKeys(RulesProfileDto profile, List<RulesProfileDto> descendants) {
private static List<String> toKeys(QProfileDto profile, List<QProfileDto> descendants) {
return Stream.concat(Stream.of(profile), descendants.stream())
.map(RulesProfileDto::getKee)
.map(QProfileDto::getKee)
.collect(MoreCollectors.toList(descendants.size() + 1));
}
}

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ExportAction.java 파일 보기

@@ -38,7 +38,7 @@ import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileExporters;
import org.sonar.server.util.LanguageParamUtils;
@@ -111,12 +111,12 @@ public class ExportAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
OrganizationDto organization = wsSupport.getOrganizationByKey(dbSession, request.param(PARAM_ORGANIZATION));
RulesProfileDto profile = loadProfile(dbSession, organization, language, name);
QProfileDto profile = loadProfile(dbSession, organization, language, name);
writeResponse(dbSession, profile, exporterKey, response);
}
}

private void writeResponse(DbSession dbSession, RulesProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
private void writeResponse(DbSession dbSession, QProfileDto profile, @Nullable String exporterKey, Response response) throws IOException {
Stream stream = response.stream();
try (
OutputStream output = response.stream().output();
@@ -131,13 +131,13 @@ public class ExportAction implements QProfileWsAction {
}
}

private RulesProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
RulesProfileDto profile;
private QProfileDto loadProfile(DbSession dbSession, OrganizationDto organization, String language, @Nullable String name) {
QProfileDto profile;
if (name == null) {
// return the default profile
profile = dbClient.qualityProfileDao().selectDefaultProfile(dbSession, organization, language);
} else {
profile = dbClient.qualityProfileDao().selectByNameAndLanguage(organization, name, language, dbSession);
profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, name, language);
}
return checkFound(profile, "Could not find profile with name '%s' for language '%s'", name, language);
}

+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/InheritanceAction.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse;
import org.sonarqube.ws.QualityProfiles.InheritanceWsResponse.QualityProfile;
@@ -71,19 +71,19 @@ public class InheritanceAction implements QProfileWsAction {
public void handle(Request request, Response response) throws Exception {
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto profile = wsSupport.getProfile(dbSession, reference);
QProfileDto profile = wsSupport.getProfile(dbSession, reference);
String organizationUuid = profile.getOrganizationUuid();
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException(String.format("Could not find organization with uuid '%s' for quality profile '%s'", organizationUuid, profile.getKee())));
List<RulesProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
List<RulesProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKee());
List<QProfileDto> ancestors = profileLookup.ancestors(profile, dbSession);
List<QProfileDto> children = dbClient.qualityProfileDao().selectChildren(dbSession, profile.getKee());
Statistics statistics = new Statistics(dbSession, organization);

writeProtobuf(buildResponse(profile, ancestors, children, statistics), request, response);
}
}

private static InheritanceWsResponse buildResponse(RulesProfileDto profile, List<RulesProfileDto> ancestors, List<RulesProfileDto> children, Statistics statistics) {
private static InheritanceWsResponse buildResponse(QProfileDto profile, List<QProfileDto> ancestors, List<QProfileDto> children, Statistics statistics) {
return InheritanceWsResponse.newBuilder()
.setProfile(buildProfile(profile, statistics))
.addAllAncestors(buildAncestors(ancestors, statistics))
@@ -91,19 +91,19 @@ public class InheritanceAction implements QProfileWsAction {
.build();
}

private static Iterable<QualityProfile> buildAncestors(List<RulesProfileDto> ancestors, Statistics statistics) {
private static Iterable<QualityProfile> buildAncestors(List<QProfileDto> ancestors, Statistics statistics) {
return ancestors.stream()
.map(ancestor -> buildProfile(ancestor, statistics))
.collect(Collectors.toList());
}

private static Iterable<QualityProfile> buildChildren(List<RulesProfileDto> children, Statistics statistics) {
private static Iterable<QualityProfile> buildChildren(List<QProfileDto> children, Statistics statistics) {
return children.stream()
.map(child -> buildProfile(child, statistics))
.collect(Collectors.toList());
}

private static QualityProfile buildProfile(RulesProfileDto qualityProfile, Statistics statistics) {
private static QualityProfile buildProfile(QProfileDto qualityProfile, Statistics statistics) {
String key = qualityProfile.getKee();
QualityProfile.Builder builder = QualityProfile.newBuilder()
.setKey(key)

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/OldRestoreAction.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class OldRestoreAction implements WsAction {
}

private void writeResponse(JsonWriter json, QProfileRestoreSummary result) {
RulesProfileDto profile = result.getProfile();
QProfileDto profile = result.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);


+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/ProjectsAction.java 파일 보기

@@ -40,7 +40,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ProjectQprofileAssociationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;

@@ -129,22 +129,22 @@ public class ProjectsAction implements QProfileWsAction {
}

private void checkProfileExists(String profileKey, DbSession session) {
if (dbClient.qualityProfileDao().selectByKey(session, profileKey) == null) {
if (dbClient.qualityProfileDao().selectByUuid(session, profileKey) == null) {
throw new NotFoundException(String.format("Could not find a quality profile with key '%s'", profileKey));
}
}

private List<ProjectQprofileAssociationDto> loadProjects(String profileKey, DbSession session, String selected, String query) {
RulesProfileDto qualityProfile = dbClient.qualityProfileDao().selectByKey(session, profileKey);
OrganizationDto organization = wsSupport.getOrganization(session, qualityProfile);
QProfileDto profile = dbClient.qualityProfileDao().selectByUuid(session, profileKey);
OrganizationDto organization = wsSupport.getOrganization(session, profile);
List<ProjectQprofileAssociationDto> projects = Lists.newArrayList();
SelectionMode selectionMode = SelectionMode.fromParam(selected);
if (SelectionMode.SELECTED == selectionMode) {
projects.addAll(dbClient.qualityProfileDao().selectSelectedProjects(organization, profileKey, query, session));
projects.addAll(dbClient.qualityProfileDao().selectSelectedProjects(session, organization, profile, query));
} else if (SelectionMode.DESELECTED == selectionMode) {
projects.addAll(dbClient.qualityProfileDao().selectDeselectedProjects(organization, profileKey, query, session));
projects.addAll(dbClient.qualityProfileDao().selectDeselectedProjects(session, organization, profile, query));
} else {
projects.addAll(dbClient.qualityProfileDao().selectProjectAssociations(organization, profileKey, query, session));
projects.addAll(dbClient.qualityProfileDao().selectProjectAssociations(session, organization, profile, query));
}
return projects;
}

+ 8
- 8
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileWsSupport.java 파일 보기

@@ -28,7 +28,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.user.UserSession;
import org.sonar.server.ws.WsUtils;
@@ -60,7 +60,7 @@ public class QProfileWsSupport {
.setExampleValue("my-org");
}

public OrganizationDto getOrganization(DbSession dbSession, RulesProfileDto profile) {
public OrganizationDto getOrganization(DbSession dbSession, QProfileDto profile) {
requireNonNull(profile);
String organizationUuid = profile.getOrganizationUuid();
return dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
@@ -80,26 +80,26 @@ public class QProfileWsSupport {
*
* @throws org.sonar.server.exceptions.NotFoundException if the specified organization or profile do not exist
*/
public RulesProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
RulesProfileDto profile;
public QProfileDto getProfile(DbSession dbSession, QProfileReference ref) {
QProfileDto profile;
if (ref.hasKey()) {
profile = dbClient.qualityProfileDao().selectByKey(dbSession, ref.getKey());
profile = dbClient.qualityProfileDao().selectByUuid(dbSession, ref.getKey());
checkFound(profile, "Quality Profile with key '%s' does not exist", ref.getKey());
} else {
OrganizationDto org = getOrganizationByKey(dbSession, ref.getOrganizationKey().orElse(null));
profile = dbClient.qualityProfileDao().selectByNameAndLanguage(org, ref.getName(), ref.getLanguage(), dbSession);
profile = dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, org, ref.getName(), ref.getLanguage());
checkFound(profile, "Quality Profile for language '%s' and name '%s' does not exist%s", ref.getLanguage(), ref.getName(),
ref.getOrganizationKey().map(o -> " in organization '" + o + "'").orElse(""));
}
return profile;
}

public void checkPermission(DbSession dbSession, RulesProfileDto rulesProfile) {
public void checkPermission(DbSession dbSession, QProfileDto rulesProfile) {
OrganizationDto organization = getOrganization(dbSession, rulesProfile);
userSession.checkPermission(OrganizationPermission.ADMINISTER_QUALITY_PROFILES, organization);
}

public void checkNotBuiltInt(RulesProfileDto profile) {
public void checkNotBuiltInt(QProfileDto profile) {
checkRequest(!profile.isBuiltIn(), "Operation forbidden for built-in Quality Profile '%s' with language '%s'", profile.getName(), profile.getLanguage());
}
}

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RemoveProjectAction.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.user.UserSession;
@@ -80,7 +80,7 @@ public class RemoveProjectAction implements QProfileWsAction {

try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto project = loadProject(dbSession, request);
RulesProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));
QProfileDto profile = wsSupport.getProfile(dbSession, QProfileReference.from(request));

if (!profile.getOrganizationUuid().equals(project.getOrganizationUuid())) {
throw new IllegalArgumentException("Project and Quality profile must have same organization");

+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RenameAction.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.user.UserSession;

@@ -89,7 +89,7 @@ public class RenameAction implements QProfileWsAction {
userSession.checkLoggedIn();

try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto qualityProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));
QProfileDto qualityProfile = wsSupport.getProfile(dbSession, QProfileReference.fromKey(profileKey));

String organizationUuid = qualityProfile.getOrganizationUuid();
userSession.checkPermission(ADMINISTER_QUALITY_PROFILES, organizationUuid);
@@ -99,7 +99,7 @@ public class RenameAction implements QProfileWsAction {
OrganizationDto organization = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid)
.orElseThrow(() -> new IllegalStateException("No organization found for uuid " + organizationUuid));
String language = qualityProfile.getLanguage();
ofNullable(dbClient.qualityProfileDao().selectByNameAndLanguage(organization, newName, language, dbSession))
ofNullable(dbClient.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, newName, language))
.ifPresent(found -> {
throw BadRequestException.create(format("Quality profile already exists: %s", newName));
});

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/RestoreAction.java 파일 보기

@@ -31,7 +31,7 @@ import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.BulkChangeResult;
import org.sonar.server.qualityprofile.QProfileBackuper;
import org.sonar.server.qualityprofile.QProfileRestoreSummary;
@@ -102,7 +102,7 @@ public class RestoreAction implements QProfileWsAction {
}

private void writeResponse(JsonWriter json, OrganizationDto organization, QProfileRestoreSummary summary) {
RulesProfileDto profile = summary.getProfile();
QProfileDto profile = summary.getProfile();
String languageKey = profile.getLanguage();
Language language = languages.get(languageKey);


+ 10
- 10
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java 파일 보기

@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.util.LanguageParamUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
@@ -156,15 +156,15 @@ public class SearchAction implements QProfileWsAction {
}
}

List<RulesProfileDto> profiles = dataLoader.findProfiles(dbSession, request, organization, project);
Set<String> defaultProfiles = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, organization.getUuid(), profiles.stream().map(RulesProfileDto::getKee).collect(MoreCollectors.toList()));
List<QProfileDto> profiles = dataLoader.findProfiles(dbSession, request, organization, project);
Set<String> defaultProfiles = dbClient.defaultQProfileDao().selectExistingQProfileUuids(dbSession, organization.getUuid(), profiles.stream().map(QProfileDto::getKee).collect(MoreCollectors.toList()));

return new SearchData()
.setOrganization(organization)
.setProfiles(profiles)
.setActiveRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesByProfileKey(dbSession, organization))
.setActiveDeprecatedRuleCountByProfileKey(dbClient.activeRuleDao().countActiveRulesForRuleStatusByProfileKey(dbSession, organization, RuleStatus.DEPRECATED))
.setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileKey(dbSession, organization))
.setProjectCountByProfileKey(dbClient.qualityProfileDao().countProjectsByProfileUuid(dbSession, organization))
.setDefaultProfileKeys(defaultProfiles);
}
}
@@ -190,12 +190,12 @@ public class SearchAction implements QProfileWsAction {
}

private SearchWsResponse buildResponse(SearchData data) {
List<RulesProfileDto> profiles = data.getProfiles();
Map<String, RulesProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(RulesProfileDto::getKee, identity()));
List<QProfileDto> profiles = data.getProfiles();
Map<String, QProfileDto> profilesByKey = profiles.stream().collect(Collectors.toMap(QProfileDto::getKee, identity()));

SearchWsResponse.Builder response = SearchWsResponse.newBuilder();

for (RulesProfileDto profile : profiles) {
for (QProfileDto profile : profiles) {
QualityProfile.Builder profileBuilder = response.addProfilesBuilder();

String profileKey = profile.getKee();
@@ -222,7 +222,7 @@ public class SearchAction implements QProfileWsAction {
return response.build();
}

private void writeLanguageFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile) {
private void writeLanguageFields(QualityProfile.Builder profileBuilder, QProfileDto profile) {
String languageKey = profile.getLanguage();
if (languageKey == null) {
return;
@@ -235,14 +235,14 @@ public class SearchAction implements QProfileWsAction {
}
}

private static void writeParentFields(QualityProfile.Builder profileBuilder, RulesProfileDto profile, Map<String, RulesProfileDto> profilesByKey) {
private static void writeParentFields(QualityProfile.Builder profileBuilder, QProfileDto profile, Map<String, QProfileDto> profilesByKey) {
String parentKey = profile.getParentKee();
if (parentKey == null) {
return;
}

profileBuilder.setParentKey(parentKey);
RulesProfileDto parent = profilesByKey.get(parentKey);
QProfileDto parent = profilesByKey.get(parentKey);
if (parent != null && parent.getName() != null) {
profileBuilder.setParentName(parent.getName());
}

+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchData.java 파일 보기

@@ -23,7 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.ImmutableList.copyOf;
@@ -31,7 +31,7 @@ import static com.google.common.collect.ImmutableMap.copyOf;

public class SearchData {
private OrganizationDto organization;
private List<RulesProfileDto> profiles;
private List<QProfileDto> profiles;
private Map<String, Long> activeRuleCountByProfileKey;
private Map<String, Long> activeDeprecatedRuleCountByProfileKey;
private Map<String, Long> projectCountByProfileKey;
@@ -46,11 +46,11 @@ public class SearchData {
return organization;
}

public List<RulesProfileDto> getProfiles() {
public List<QProfileDto> getProfiles() {
return profiles;
}

public SearchData setProfiles(List<RulesProfileDto> profiles) {
public SearchData setProfiles(List<QProfileDto> profiles) {
this.profiles = copyOf(profiles);
return this;
}
@@ -82,7 +82,7 @@ public class SearchData {
return firstNonNull(activeDeprecatedRuleCountByProfileKey.get(profileKey), 0L);
}

boolean isDefault(RulesProfileDto profile) {
boolean isDefault(QProfileDto profile) {
return defaultProfileKeys.contains(profile.getKee());
}


+ 19
- 19
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchDataLoader.java 파일 보기

@@ -36,7 +36,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.qualityprofile.QProfileLookup;
import org.sonarqube.ws.client.qualityprofile.SearchWsRequest;

@@ -44,9 +44,9 @@ import static java.lang.String.format;

public class SearchDataLoader {

private static final Comparator<RulesProfileDto> Q_PROFILE_COMPARATOR = Comparator
.comparing(RulesProfileDto::getLanguage)
.thenComparing(RulesProfileDto::getName);
private static final Comparator<QProfileDto> Q_PROFILE_COMPARATOR = Comparator
.comparing(QProfileDto::getLanguage)
.thenComparing(QProfileDto::getName);

private final Languages languages;
private final QProfileLookup profileLookup;
@@ -59,8 +59,8 @@ public class SearchDataLoader {
}

@VisibleForTesting
List<RulesProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
Collection<RulesProfileDto> profiles;
List<QProfileDto> findProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, @Nullable ComponentDto project) {
Collection<QProfileDto> profiles;
if (askDefaultProfiles(request)) {
profiles = findDefaultProfiles(dbSession, request, organization);
} else if (project != null) {
@@ -72,11 +72,11 @@ public class SearchDataLoader {
return profiles.stream().sorted(Q_PROFILE_COMPARATOR).collect(Collectors.toList());
}

private Collection<RulesProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
private Collection<QProfileDto> findDefaultProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String profileName = request.getProfileName();

Set<String> languageKeys = getLanguageKeys();
Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
Map<String, QProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());

Set<String> missingLanguageKeys = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
Set<String> noDefaultProfileLanguageKeys = lookupDefaults(dbSession, organization, qualityProfiles, missingLanguageKeys);
@@ -88,11 +88,11 @@ public class SearchDataLoader {
return qualityProfiles.values();
}

private Collection<RulesProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
private Collection<QProfileDto> findProjectProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization, ComponentDto project) {
String profileName = request.getProfileName();

Set<String> languageKeys = getLanguageKeys();
Map<String, RulesProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());
Map<String, QProfileDto> qualityProfiles = new HashMap<>(languageKeys.size());

// look up profiles by profileName (if any) for each language
Set<String> unresolvedLanguages = lookupByProfileName(dbSession, organization, qualityProfiles, languageKeys, profileName);
@@ -108,7 +108,7 @@ public class SearchDataLoader {
return qualityProfiles.values();
}

private List<RulesProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
private Collection<QProfileDto> findAllProfiles(DbSession dbSession, SearchWsRequest request, OrganizationDto organization) {
String language = request.getLanguage();

if (language == null) {
@@ -117,20 +117,20 @@ public class SearchDataLoader {
return profileLookup.profiles(dbSession, language, organization);
}

private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
@Nullable String profileName) {
private Set<String> lookupByProfileName(DbSession dbSession, OrganizationDto organization, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys,
@Nullable String profileName) {
if (languageKeys.isEmpty() || profileName == null) {
return languageKeys;
}

dbClient.qualityProfileDao().selectByNameAndLanguages(organization, profileName, languageKeys, dbSession)
dbClient.qualityProfileDao().selectByNameAndLanguages(dbSession, organization, profileName, languageKeys)
.forEach(qualityProfile -> qualityProfiles
.put(qualityProfile.getLanguage(), qualityProfile));
return difference(languageKeys, qualityProfiles.keySet());
}

private Set<String> lookupByModule(DbSession dbSession, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys,
ComponentDto project) {
private Set<String> lookupByModule(DbSession dbSession, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys,
ComponentDto project) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -140,7 +140,7 @@ public class SearchDataLoader {
return difference(languageKeys, qualityProfiles.keySet());
}

private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, RulesProfileDto> qualityProfiles, Set<String> languageKeys) {
private Set<String> lookupDefaults(DbSession dbSession, OrganizationDto organization, Map<String, QProfileDto> qualityProfiles, Set<String> languageKeys) {
if (languageKeys.isEmpty()) {
return languageKeys;
}
@@ -153,7 +153,7 @@ public class SearchDataLoader {
return Sets.newHashSet(Sets.difference(languageKeys, set2));
}

private static void addAll(Map<String, RulesProfileDto> qualityProfiles, Collection<RulesProfileDto> list) {
private static void addAll(Map<String, QProfileDto> qualityProfiles, Collection<QProfileDto> list) {
list.forEach(qualityProfile -> qualityProfiles.put(qualityProfile.getLanguage(), qualityProfile));
}

@@ -161,7 +161,7 @@ public class SearchDataLoader {
return Arrays.stream(languages.all()).map(Language::getKey).collect(Collectors.toSet());
}

private List<RulesProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
private List<QProfileDto> findDefaultProfiles(final DbSession dbSession, OrganizationDto organization, Set<String> languageKeys) {
return dbClient.qualityProfileDao().selectDefaultProfiles(dbSession, organization, languageKeys);
}


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SetDefaultAction.java 파일 보기

@@ -27,7 +27,7 @@ import org.sonar.api.server.ws.WebService.NewAction;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.user.UserSession;

import static java.lang.String.format;
@@ -66,7 +66,7 @@ public class SetDefaultAction implements QProfileWsAction {
userSession.checkLoggedIn();
QProfileReference reference = QProfileReference.from(request);
try (DbSession dbSession = dbClient.openSession(false)) {
RulesProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
QProfileDto qualityProfile = qProfileWsSupport.getProfile(dbSession, reference);
dbClient.organizationDao().selectByUuid(dbSession, qualityProfile.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(
format("Cannot find organization '%s' for quality profile '%s'", qualityProfile.getOrganizationUuid(), qualityProfile.getKee())));
@@ -77,7 +77,7 @@ public class SetDefaultAction implements QProfileWsAction {
response.noContent();
}

public void setDefault(DbSession dbSession, RulesProfileDto profile) {
public void setDefault(DbSession dbSession, QProfileDto profile) {
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profile));
}
}

+ 0
- 3
server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleIndexDefinition.java 파일 보기

@@ -78,7 +78,6 @@ public class RuleIndexDefinition implements IndexDefinition {
public static final String FIELD_ACTIVE_RULE_PROFILE_KEY = "profile";
public static final String FIELD_ACTIVE_RULE_SEVERITY = "severity";
public static final String FIELD_ACTIVE_RULE_RULE_KEY = "ruleKey";
public static final String FIELD_ACTIVE_RULE_CREATED_AT = "createdAt";
public static final String FIELD_ACTIVE_RULE_UPDATED_AT = "updatedAt";

private final Settings settings;
@@ -106,8 +105,6 @@ public class RuleIndexDefinition implements IndexDefinition {
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_KEY).disableNorms().build();
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();

activeRuleMapping.createLongField(FIELD_ACTIVE_RULE_CREATED_AT);
activeRuleMapping.createLongField(FIELD_ACTIVE_RULE_UPDATED_AT);

// Rule extension type

+ 7
- 7
server/sonar-server/src/main/java/org/sonar/server/rule/ws/ActiveRuleCompleter.java 파일 보기

@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.qualityprofile.ActiveRule;
@@ -178,10 +178,10 @@ public class ActiveRuleCompleter {
}

private Rules.QProfiles.Builder buildQProfiles(DbSession dbSession, Collection<String> harvestedProfileKeys) {
Map<String, RulesProfileDto> qProfilesByKey = new HashMap<>();
Map<String, QProfileDto> qProfilesByKey = new HashMap<>();
for (String qProfileKey : harvestedProfileKeys) {
if (!qProfilesByKey.containsKey(qProfileKey)) {
RulesProfileDto profile = loadProfile(dbSession, qProfileKey);
QProfileDto profile = loadProfile(dbSession, qProfileKey);
if (profile == null) {
LOG.warn("Could not find quality profile with key " + qProfileKey);
continue;
@@ -196,7 +196,7 @@ public class ActiveRuleCompleter {

Rules.QProfiles.Builder qProfilesResponse = Rules.QProfiles.newBuilder();
Map<String, Rules.QProfile> qProfilesMapResponse = qProfilesResponse.getMutableQProfiles();
for (RulesProfileDto profile : qProfilesByKey.values()) {
for (QProfileDto profile : qProfilesByKey.values()) {
writeProfile(qProfilesMapResponse, profile);
}

@@ -204,11 +204,11 @@ public class ActiveRuleCompleter {
}

@CheckForNull
private RulesProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
return dbClient.qualityProfileDao().selectByKey(dbSession, qProfileKey);
private QProfileDto loadProfile(DbSession dbSession, String qProfileKey) {
return dbClient.qualityProfileDao().selectByUuid(dbSession, qProfileKey);
}

private void writeProfile(Map<String, Rules.QProfile> profilesResponse, RulesProfileDto profile) {
private void writeProfile(Map<String, Rules.QProfile> profilesResponse, QProfileDto profile) {
Rules.QProfile.Builder profileResponse = Rules.QProfile.newBuilder();
setNullable(profile.getName(), profileResponse::setName);


+ 3
- 3
server/sonar-server/src/main/java/org/sonar/server/rule/ws/AppAction.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.OrganizationPermission;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.user.UserSession;

import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_ORGANIZATION;
@@ -87,7 +87,7 @@ public class AppAction implements RulesWsAction {

private void addProfiles(DbSession dbSession, OrganizationDto organization, JsonWriter json) {
json.name("qualityprofiles").beginArray();
for (RulesProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
for (QProfileDto profile : dbClient.qualityProfileDao().selectAll(dbSession, organization)) {
if (languageIsSupported(profile)) {
json
.beginObject()
@@ -102,7 +102,7 @@ public class AppAction implements RulesWsAction {
json.endArray();
}

private boolean languageIsSupported(RulesProfileDto profile) {
private boolean languageIsSupported(QProfileDto profile) {
return languages.get(profile.getLanguage()) != null;
}


+ 5
- 5
server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.ws.WsUtils;

@@ -88,8 +88,8 @@ public class RuleQueryFactory {
organizationUuid = wsSupport.getOrganizationByKey(dbSession, organizationKey).getUuid();
languages = request.paramAsStrings(PARAM_LANGUAGES);
} else {
RulesProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey);
RulesProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
QProfileDto qualityProfileOptional = dbClient.qualityProfileDao().selectByUuid(dbSession, qualityProfileKey);
QProfileDto qualityProfile = WsUtils.checkFound(qualityProfileOptional, "The specified qualityProfile '%s' does not exist", qualityProfileKey);
query.setQProfileKey(qualityProfileKey);
languages = ImmutableList.of(qualityProfile.getLanguage());
organizationUuid = qualityProfile.getOrganizationUuid();
@@ -121,8 +121,8 @@ public class RuleQueryFactory {
}

@CheckForNull
private RulesProfileDto getProfileByKey(DbSession dbSession, String key) {
return dbClient.qualityProfileDao().selectByKey(dbSession, key);
private QProfileDto getProfileByKey(DbSession dbSession, String key) {
return dbClient.qualityProfileDao().selectByUuid(dbSession, key);
}

}

+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectDataLoaderMediumTest.java 파일 보기

@@ -38,7 +38,7 @@ import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.qualityprofile.DefaultQProfileDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.source.FileSourceDao;
import org.sonar.db.source.FileSourceDto;
import org.sonar.db.source.FileSourceDto.Type;
@@ -605,7 +605,7 @@ public class ProjectDataLoaderMediumTest {
private void addDefaultProfile() {
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto, false);
RulesProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
QProfileDto profileDto = newQProfileDto(organizationDto, QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt(
formatDateTime(new Date()));
dbClient.qualityProfileDao().insert(dbSession, profileDto);
dbClient.defaultQProfileDao().insertOrUpdate(dbSession, DefaultQProfileDto.from(profileDto));

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStepTest.java 파일 보기

@@ -274,7 +274,7 @@ public class LoadReportAnalysisMetadataHolderStepTest {
metadataBuilder.getMutableQprofilesPerLanguage().put("js", ScannerReport.Metadata.QProfile.newBuilder().setKey("p1").setName("Sonar way").setLanguage("js").build());
reportReader.setMetadata(metadataBuilder.build());

dbTester.qualityProfiles().insert(organization, p -> p.setLanguage("js"), p -> p.setKey("p1"));
dbTester.qualityProfiles().insert(organization, p -> p.setLanguage("js").setKey("p1"));

ComputationStep underTest = createStep(createCeTask(PROJECT_KEY, organization.getUuid()));

@@ -292,8 +292,8 @@ public class LoadReportAnalysisMetadataHolderStepTest {
metadataBuilder.getMutableQprofilesPerLanguage().put("php", ScannerReport.Metadata.QProfile.newBuilder().setKey("phpInOrg2").setName("PHP way").setLanguage("php").build());
reportReader.setMetadata(metadataBuilder.build());

dbTester.qualityProfiles().insert(organization1, p -> p.setLanguage("js"), p -> p.setKey("jsInOrg1"));
dbTester.qualityProfiles().insert(organization2, p -> p.setLanguage("php"), p -> p.setKey("phpInOrg2"));
dbTester.qualityProfiles().insert(organization1, p -> p.setLanguage("js").setKey("jsInOrg1"));
dbTester.qualityProfiles().insert(organization2, p -> p.setLanguage("php").setKey("phpInOrg2"));

ComputationStep underTest = createStep(createCeTask(PROJECT_KEY, organization1.getUuid()));


+ 16
- 16
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/UpdateQualityProfilesLastUsedDateStepTest.java 파일 보기

@@ -32,7 +32,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent;
@@ -51,9 +51,9 @@ import static org.sonar.db.qualityprofile.QualityProfileTesting.newQualityProfil
public class UpdateQualityProfilesLastUsedDateStepTest {
static final long ANALYSIS_DATE = 1_123_456_789L;
private static final Component PROJECT = ReportComponent.DUMB_PROJECT;
private RulesProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
private RulesProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
private RulesProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");
private QProfileDto sonarWayJava = newQualityProfileDto().setKey("sonar-way-java");
private QProfileDto sonarWayPhp = newQualityProfileDto().setKey("sonar-way-php");
private QProfileDto myQualityProfile = newQualityProfileDto().setKey("my-qp");

@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -81,7 +81,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest {

@Test
public void doest_not_update_profiles_when_no_measure() {
qualityProfileDb.insertQualityProfiles(sonarWayJava, sonarWayPhp, myQualityProfile);
qualityProfileDb.insert(sonarWayJava, sonarWayPhp, myQualityProfile);

underTest.execute();

@@ -92,7 +92,7 @@ public class UpdateQualityProfilesLastUsedDateStepTest {

@Test
public void update_profiles_defined_in_quality_profiles_measure() {
qualityProfileDb.insertQualityProfiles(sonarWayJava, sonarWayPhp, myQualityProfile);
qualityProfileDb.insert(sonarWayJava, sonarWayPhp, myQualityProfile);

measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(
toJson(sonarWayJava.getKee(), myQualityProfile.getKee())));
@@ -107,13 +107,13 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
@Test
public void ancestor_profiles_are_updated() throws Exception {
// Parent profiles should be updated
RulesProfileDto rootProfile = newQualityProfileDto().setKey("root");
RulesProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKee());
QProfileDto rootProfile = newQualityProfileDto().setKey("root");
QProfileDto parentProfile = newQualityProfileDto().setKey("parent").setParentKee(rootProfile.getKee());
// Current profile => should be updated
RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKee());
QProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee(parentProfile.getKee());
// Child of current profile => should not be updated
RulesProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKee());
qualityProfileDb.insertQualityProfiles(rootProfile, parentProfile, currentProfile, childProfile);
QProfileDto childProfile = newQualityProfileDto().setKey("child").setParentKee(currentProfile.getKee());
qualityProfileDb.insert(rootProfile, parentProfile, currentProfile, childProfile);

measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee())));

@@ -127,8 +127,8 @@ public class UpdateQualityProfilesLastUsedDateStepTest {

@Test
public void fail_when_profile_is_linked_to_unknown_parent() throws Exception {
RulesProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
qualityProfileDb.insertQualityProfiles(currentProfile);
QProfileDto currentProfile = newQualityProfileDto().setKey("current").setParentKee("unknown");
qualityProfileDb.insert(currentProfile);

measureRepository.addRawMeasure(1, QUALITY_PROFILES_KEY, Measure.newMeasureBuilder().create(toJson(currentProfile.getKee())));

@@ -141,17 +141,17 @@ public class UpdateQualityProfilesLastUsedDateStepTest {
assertThat(underTest.getDescription()).isEqualTo("Update last usage date of quality profiles");
}

private void assertQualityProfileIsUpdated(RulesProfileDto qp) {
private void assertQualityProfileIsUpdated(QProfileDto qp) {
assertThat(selectLastUser(qp.getKee())).withFailMessage("Quality profile '%s' hasn't been updated. Value: %d", qp.getKee(), qp.getLastUsed()).isEqualTo(ANALYSIS_DATE);
}

private void assertQualityProfileIsTheSame(RulesProfileDto qp) {
private void assertQualityProfileIsTheSame(QProfileDto qp) {
assertThat(selectLastUser(qp.getKee())).isEqualTo(qp.getLastUsed());
}

@CheckForNull
private Long selectLastUser(String qualityProfileKey) {
return dbClient.qualityProfileDao().selectByKey(dbSession, qualityProfileKey).getLastUsed();
return dbClient.qualityProfileDao().selectByUuid(dbSession, qualityProfileKey).getLastUsed();
}

private static String toJson(String... keys) {

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java 파일 보기

@@ -37,7 +37,7 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.ComponentCleanerService;
@@ -321,8 +321,8 @@ public class DeleteActionTest {
public void request_also_deletes_quality_profiles_of_specified_organization() {
OrganizationDto org = db.organizations().insert();
OrganizationDto otherOrg = db.organizations().insert();
RulesProfileDto profileInOrg = db.qualityProfiles().insert(org);
RulesProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);
QProfileDto profileInOrg = db.qualityProfiles().insert(org);
QProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);

logInAsAdministrator(org);


+ 9
- 9
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java 파일 보기

@@ -44,7 +44,7 @@ import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.ActiveRuleDao;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -126,14 +126,14 @@ public class QProfileBackuperMediumTest {
ruleIndexer.indexRuleDefinition(blahRule.getKey());

// create profile P1 with rules x2 and x1 activated
RulesProfileDto profile = newXooP1(organization);
QProfileDto profile = newXooP1(organization);
db.qualityProfileDao().insert(dbSession, profile);
RuleActivation activation1 = new RuleActivation(XOO_X2).setSeverity("MINOR");
RuleActivation activation2 = new RuleActivation(XOO_X1);
RuleActivation activation3 = new RuleActivation(blahRuleKey);
activation2.setSeverity(Severity.BLOCKER);
activation2.setParameter("max", "7");
RulesProfileDto profileDto = get(XOO_P1_NAME);
QProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation1, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation2, profileDto);
tester.get(RuleActivator.class).activate(dbSession, activation3, profileDto);
@@ -156,7 +156,7 @@ public class QProfileBackuperMediumTest {
organization, null);

// Check in db
RulesProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
QProfileDto profile = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertThat(profile).isNotNull();

List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, profile.getKee());
@@ -182,7 +182,7 @@ public class QProfileBackuperMediumTest {
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(Severity.INFO);
activation.setParameter("max", "10");
RulesProfileDto profileDto = get(XOO_P1_NAME);
QProfileDto profileDto = get(XOO_P1_NAME);
tester.get(RuleActivator.class).activate(dbSession, activation, profileDto);

activation = new RuleActivation(XOO_X2);
@@ -379,7 +379,7 @@ public class QProfileBackuperMediumTest {
List<ActiveRuleDto> activeRules = db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY);
assertThat(activeRules).hasSize(0);

RulesProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(organization, "P3", "xoo", dbSession);
QProfileDto target = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P3", "xoo");
assertThat(target).isNotNull();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, target.getKee())).hasSize(1);
}
@@ -392,7 +392,7 @@ public class QProfileBackuperMediumTest {

dbSession.clearCache();
assertThat(anyActiveRuleExists()).isFalse();
List<RulesProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
List<QProfileDto> profiles = db.qualityProfileDao().selectAll(dbSession, organization);
assertThat(profiles).hasSize(1);
assertThat(profiles.get(0).getName()).isEqualTo("P1");
}
@@ -404,7 +404,7 @@ public class QProfileBackuperMediumTest {
}
}

private RulesProfileDto get(QProfileName profileName) {
return db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
private QProfileDto get(QProfileName profileName) {
return db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, profileName.getName(), profileName.getLanguage());
}
}

+ 3
- 3
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileComparisonMediumTest.java 파일 보기

@@ -30,7 +30,7 @@ import org.sonar.api.rule.Severity;
import org.sonar.api.server.rule.RuleParamType;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
@@ -56,8 +56,8 @@ public class QProfileComparisonMediumTest {

RuleDto xooRule1;
RuleDto xooRule2;
RulesProfileDto left;
RulesProfileDto right;
QProfileDto left;
QProfileDto right;

@Before
public void before() {

+ 4
- 4
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileCopierMediumTest.java 파일 보기

@@ -35,7 +35,7 @@ import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.ActiveRuleParamDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
@@ -65,7 +65,7 @@ public class QProfileCopierMediumTest {
private RuleIndexer ruleIndexer;
private ActiveRuleIndexer activeRuleIndexer;
private OrganizationDto organization;
private RulesProfileDto sourceProfile;
private QProfileDto sourceProfile;

@Before
public void before() {
@@ -169,7 +169,7 @@ public class QProfileCopierMediumTest {
copier.copyToName(dbSession, sourceProfile, QProfileTesting.XOO_P2_NAME.getName());

verifyOneActiveRule(QProfileTesting.XOO_P2_KEY, Severity.BLOCKER, ActiveRuleDto.INHERITED, ImmutableMap.of("max", "7"));
RulesProfileDto profile2Dto = db.qualityProfileDao().selectByKey(dbSession, QProfileTesting.XOO_P2_KEY);
QProfileDto profile2Dto = db.qualityProfileDao().selectByUuid(dbSession, QProfileTesting.XOO_P2_KEY);
assertThat(profile2Dto.getParentKee()).isEqualTo(QProfileTesting.XOO_P1_KEY);
}

@@ -193,7 +193,7 @@ public class QProfileCopierMediumTest {

private void verifyOneActiveRule(QProfileName profileName, String expectedSeverity,
@Nullable String expectedInheritance, Map<String, String> expectedParams) {
RulesProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(organization, profileName.getName(), profileName.getLanguage(), dbSession);
QProfileDto dto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, profileName.getName(), profileName.getLanguage());
verifyOneActiveRule(dto.getKee(), expectedSeverity, expectedInheritance, expectedParams);
}


+ 2
- 2
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileExportersTest.java 파일 보기

@@ -41,7 +41,7 @@ import org.sonar.api.utils.ValidationMessages;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleDto;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
import org.sonar.server.rule.index.RuleIndex;
@@ -102,7 +102,7 @@ public class QProfileExportersTest {

@Test
public void import_xml() {
RulesProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
QProfileDto profileDto = QProfileTesting.newQProfileDto("org-123", QProfileName.createFor("xoo", "import_xml"), "import_xml");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();


+ 6
- 6
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java 파일 보기

@@ -29,7 +29,7 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.qualityprofile.RulesProfileDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
@@ -69,7 +69,7 @@ public class QProfileFactoryMediumTest {
public void checkAndCreate() {
String uuid = organization.getUuid();

RulesProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
QProfileDto writtenDto = factory.checkAndCreateCustom(dbSession, organization, new QProfileName("xoo", "P1"));
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -80,7 +80,7 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.isBuiltIn()).isFalse();

// reload the dto
RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
QProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertEqual(writtenDto, readDto);

assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -90,7 +90,7 @@ public class QProfileFactoryMediumTest {
public void create() {
String uuid = organization.getUuid();

RulesProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
QProfileDto writtenDto = factory.createBuiltIn(dbSession, organization, new QProfileName("xoo", "P1"), true);
dbSession.commit();
dbSession.clearCache();
assertThat(writtenDto.getOrganizationUuid()).isEqualTo(uuid);
@@ -101,7 +101,7 @@ public class QProfileFactoryMediumTest {
assertThat(writtenDto.getParentKee()).isNull();

// reload the dto
RulesProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(organization, "P1", "xoo", dbSession);
QProfileDto readDto = db.qualityProfileDao().selectByNameAndLanguage(dbSession, organization, "P1", "xoo");
assertEqual(writtenDto, readDto);

assertThat(db.qualityProfileDao().selectAll(dbSession, organization)).hasSize(1);
@@ -170,7 +170,7 @@ public class QProfileFactoryMediumTest {
thrown.expectMessage(message);
}

private static void assertEqual(RulesProfileDto writtenDto, RulesProfileDto readDto) {
private static void assertEqual(QProfileDto writtenDto, QProfileDto readDto) {
assertThat(readDto.getOrganizationUuid()).isEqualTo(writtenDto.getOrganizationUuid());
assertThat(readDto.getName()).isEqualTo(writtenDto.getName());
assertThat(readDto.getKee()).startsWith(writtenDto.getKee());

+ 0
- 0
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryTest.java 파일 보기


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.

Loading…
취소
저장