diff options
author | Godin <mandrikov@gmail.com> | 2010-12-21 00:20:07 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-21 00:20:07 +0000 |
commit | c20e334b230bc4cd12d0d13746b8e7828550cb80 (patch) | |
tree | 8cf0605bd0bf3eb8b5c8f633f90454e787c605e4 /sonar-server/src/main/java | |
parent | c365b36cf4b231555de68b193a765502d9d28bbb (diff) | |
download | sonarqube-c20e334b230bc4cd12d0d13746b8e7828550cb80.tar.gz sonarqube-c20e334b230bc4cd12d0d13746b8e7828550cb80.zip |
SONAR-1722: Change RulesProfile.parentId to RulesProfile.parentName in order to simplify backup
SONAR-2052: Add test for backup of inherited profiles
Diffstat (limited to 'sonar-server/src/main/java')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java | 33 | ||||
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java | 4 |
2 files changed, 28 insertions, 9 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index c5c118dc1cb..549f71742f2 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -73,11 +73,12 @@ public class ProfilesManager extends BaseDao { // Managing inheritance of profiles // Only one level of inheritance supported - public void changeParentProfile(Integer profileId, Integer parentId) { + public void changeParentProfile(Integer profileId, String parentName) { RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); - if (profile != null && !profile.getProvided() && profileId != parentId) { - RulesProfile oldParent = getProfile(profile.getParentId()); - RulesProfile newParent = getProfile(parentId); + // TODO check cycles + if (profile != null && !profile.getProvided()) { + RulesProfile oldParent = getParentProfile(profile); + RulesProfile newParent = getProfile(profile.getLanguage(), parentName); // Deactivate all inherited rules if (oldParent != null) { for (ActiveRule activeRule : oldParent.getActiveRules()) { @@ -89,8 +90,9 @@ public class ProfilesManager extends BaseDao { for (ActiveRule activeRule : newParent.getActiveRules()) { activateOrChange(profile, activeRule); } + } else { } - profile.setParentId(parentId); + profile.setParentName(newParent == null ? null : newParent.getName()); getSession().saveWithoutFlush(profile); getSession().commit(); } @@ -128,7 +130,7 @@ public class ProfilesManager extends BaseDao { RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); if (activeRule != null && activeRule.isInherited() && activeRule.isOverrides()) { - ActiveRule parentActiveRule = getProfile(profile.getParentId()).getActiveRule(activeRule.getRule()); + ActiveRule parentActiveRule = getParentProfile(profile).getActiveRule(activeRule.getRule()); removeActiveRule(profile, activeRule); activeRule = (ActiveRule) parentActiveRule.clone(); activeRule.setRulesProfile(profile); @@ -170,7 +172,11 @@ public class ProfilesManager extends BaseDao { } private List<RulesProfile> getChildren(int parentId) { - return getSession().getResults(RulesProfile.class, "parentId", parentId, "provided", false); + RulesProfile parent = getProfile(parentId); + return getSession().getResults(RulesProfile.class, + "language", parent.getLanguage(), + "parentName", parent.getName(), + "provided", false); } private void removeActiveRule(RulesProfile profile, ActiveRule activeRule) { @@ -182,4 +188,17 @@ public class ProfilesManager extends BaseDao { return id == null ? null : getSession().getEntity(RulesProfile.class, id); } + private RulesProfile getProfile(String language, String name) { + return getSession().getSingleResult(RulesProfile.class, + "language", language, + "name", name); + } + + private RulesProfile getParentProfile(RulesProfile profile) { + if (profile.getParentName() == null) { + return null; + } + return getProfile(profile.getLanguage(), profile.getParentName()); + } + } diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 1808547126f..d4e89669dbd 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -197,8 +197,8 @@ public final class JRubyFacade implements ServerComponent { getProfilesManager().deleteProfile((int) profileId); } - public void changeParentProfile(int profileId, Integer parentId) { - getProfilesManager().changeParentProfile(profileId, parentId); + public void changeParentProfile(int profileId, String parentName) { + getProfilesManager().changeParentProfile(profileId, parentName); } public void ruleActivatedOrChanged(int parentProfileId, int activeRuleId) { |