From: Evgeny Mandrikov Date: Tue, 31 May 2011 20:01:05 +0000 (+0400) Subject: SONAR-1922 Improve UI for profile changelog X-Git-Tag: 2.9~101 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=94c39df6941f641936159e3d3bed0d2bd6120c07;p=sonarqube.git SONAR-1922 Improve UI for profile changelog * Removed useless version column from Quality Profiles page. * To improve readability - version of profile displayed in a dedicated column on Changelog page, otherwise it can be difficult to determine version associated to a row. * Allowed to select both versions to compare. * CSS attribute "word-wrap" was set to "break-word" to decrease width of table, when parameter value too huge. Tested in Chromimum 12.0.742.68 and in Firefox 3.6.17. * Version of profile was added to widget. * Save and show username instead of login. --- diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb index a7d1b64bdc2..1891e837e47 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/description.html.erb @@ -21,7 +21,7 @@ %> Profile: - <%= link_to profile_measure.data, {:controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i}, :id => 'profile_link' -%> + <%= link_to profile_measure.data, {:controller => '/rules_configuration', :action => 'index', :id => profile_measure.value.to_i}, :id => 'profile_link' -%> (version <%= format_measure('profile_version', :default => '1') -%>) <% end %> <% if Project::SCOPE_SET==@project.scope %> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java index 20b0ee861c0..13f8818d0bc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/TimeMachineQuery.java @@ -19,8 +19,6 @@ */ package org.sonar.api.batch; -import org.apache.commons.lang.builder.EqualsBuilder; - import com.google.common.collect.Lists; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.measures.Metric; @@ -233,10 +231,4 @@ public class TimeMachineQuery { .append("to", to) .toString(); } - - @Override - public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java index a3b95213220..e9373e73bc8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleChange.java @@ -19,37 +19,30 @@ */ package org.sonar.api.rules; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.BaseIdentifiable; import org.sonar.api.profiles.RulesProfile; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.persistence.*; + /** * A class to map a RuleChange to the hibernate model - * + * * @since 2.9 */ @Entity @Table(name = "active_rule_changes") public class ActiveRuleChange extends BaseIdentifiable { - @Column(name = "user_login", updatable = false, nullable = false) - private String modifierLogin; + @Column(name = "user_name", updatable = false, nullable = false) + private String userName; @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "profile_id", updatable = false, nullable = false) @@ -80,12 +73,12 @@ public class ActiveRuleChange extends BaseIdentifiable { @Column(name = "new_severity", updatable = false, nullable = true) @Enumerated(EnumType.ORDINAL) private RulePriority newSeverity; - + @OneToMany(mappedBy = "activeRuleChange", fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE }) private List activeRuleParamChanges = new ArrayList(); - public ActiveRuleChange(String modifierLogin, RulesProfile profile, Rule rule) { - this.modifierLogin = modifierLogin; + public ActiveRuleChange(String userName, RulesProfile profile, Rule rule) { + this.userName = userName; this.rulesProfile = profile; this.profileVersion = profile.getVersion(); this.rule = rule; @@ -150,8 +143,8 @@ public class ActiveRuleChange extends BaseIdentifiable { return activeRuleParamChanges; } - public String getModifierLogin() { - return modifierLogin; + public String getUserName() { + return userName; } public ActiveRuleChange setParameterChange(String key, String oldValue, String newValue) { @@ -176,7 +169,7 @@ public class ActiveRuleChange extends BaseIdentifiable { ActiveRuleChange rhs = (ActiveRuleChange) obj; return new EqualsBuilder() .appendSuper(super.equals(obj)) - .append(modifierLogin, rhs.modifierLogin) + .append(userName, rhs.userName) .append(rulesProfile, rhs.rulesProfile) .append(rule, rhs.rule) .append(date, rhs.date) @@ -188,7 +181,7 @@ public class ActiveRuleChange extends BaseIdentifiable { @Override public int hashCode() { return new HashCodeBuilder(41, 33) - .append(modifierLogin) + .append(userName) .append(rulesProfile) .append(rule) .append(date) @@ -203,7 +196,7 @@ public class ActiveRuleChange extends BaseIdentifiable { .append("id", getId()) .append("profile", rulesProfile) .append("rule", rule) - .append("modifier", modifierLogin) + .append("modifier", userName) .append("changed at", date) .append("enabled", enabled) .append("new severity", newSeverity) 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 4c96afe019e..63d1d996cc9 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 @@ -19,6 +19,7 @@ */ package org.sonar.server.configuration; +import org.apache.commons.lang.ObjectUtils; import org.codehaus.plexus.util.StringUtils; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; @@ -94,7 +95,7 @@ public class ProfilesManager extends BaseDao { // Managing inheritance of profiles - public ValidationMessages changeParentProfile(Integer profileId, String parentName, String userLogin) { + public ValidationMessages changeParentProfile(Integer profileId, String parentName, String userName) { ValidationMessages messages = ValidationMessages.create(); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); if (profile != null && !profile.getProvided()) { @@ -107,13 +108,13 @@ public class ProfilesManager extends BaseDao { // Deactivate all inherited rules if (oldParent != null) { for (ActiveRule activeRule : oldParent.getActiveRules()) { - deactivate(profile, activeRule.getRule(), userLogin); + deactivate(profile, activeRule.getRule(), userName); } } // Activate all inherited rules if (newParent != null) { for (ActiveRule activeRule : newParent.getActiveRules()) { - activateOrChange(profile, activeRule, userLogin); + activateOrChange(profile, activeRule, userName); } } profile.setParentName(newParent == null ? null : newParent.getName()); @@ -126,51 +127,51 @@ public class ProfilesManager extends BaseDao { /** * Rule was activated */ - public void activated(int profileId, int activeRuleId, String userLogin) { + public void activated(int profileId, int activeRuleId, String userName) { ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); - ruleEnabled(profile, activeRule, userLogin); + ruleEnabled(profile, activeRule, userName); // Notify child profiles - activatedOrChanged(profileId, activeRuleId, userLogin); + activatedOrChanged(profileId, activeRuleId, userName); } /** * Rule param was changed */ - public void ruleParamChanged(int profileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userLogin) { + public void ruleParamChanged(int profileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) { ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); - ruleParamChanged(profile, activeRule.getRule(), paramKey, oldValue, newValue, userLogin); + ruleParamChanged(profile, activeRule.getRule(), paramKey, oldValue, newValue, userName); // Notify child profiles - activatedOrChanged(profileId, activeRuleId, userLogin); + activatedOrChanged(profileId, activeRuleId, userName); } /** * Rule severity was changed */ - public void ruleSeverityChanged(int profileId, int activeRuleId, RulePriority oldSeverity, RulePriority newSeverity, String userLogin) { + public void ruleSeverityChanged(int profileId, int activeRuleId, RulePriority oldSeverity, RulePriority newSeverity, String userName) { ActiveRule activeRule = getSession().getEntity(ActiveRule.class, activeRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); - ruleSeverityChanged(profile, activeRule.getRule(), oldSeverity, newSeverity, userLogin); + ruleSeverityChanged(profile, activeRule.getRule(), oldSeverity, newSeverity, userName); // Notify child profiles - activatedOrChanged(profileId, activeRuleId, userLogin); + activatedOrChanged(profileId, activeRuleId, userName); } /** * Rule was activated/changed in parent profile. */ - private void activatedOrChanged(int parentProfileId, int activeRuleId, String userLogin) { + private void activatedOrChanged(int parentProfileId, int activeRuleId, String userName) { ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId); if (parentActiveRule.isInherited()) { parentActiveRule.setInheritance(ActiveRule.OVERRIDES); getSession().saveWithoutFlush(parentActiveRule); } for (RulesProfile child : getChildren(parentProfileId)) { - activateOrChange(child, parentActiveRule, userLogin); + activateOrChange(child, parentActiveRule, userName); } getSession().commit(); } @@ -178,12 +179,12 @@ public class ProfilesManager extends BaseDao { /** * Rule was deactivated in parent profile. */ - public void deactivated(int parentProfileId, int deactivatedRuleId, String userLogin) { + public void deactivated(int parentProfileId, int deactivatedRuleId, String userName) { ActiveRule parentActiveRule = getSession().getEntity(ActiveRule.class, deactivatedRuleId); RulesProfile profile = getSession().getEntity(RulesProfile.class, parentProfileId); - ruleDisabled(profile, parentActiveRule, userLogin); + ruleDisabled(profile, parentActiveRule, userName); for (RulesProfile child : getChildren(parentProfileId)) { - deactivate(child, parentActiveRule.getRule(), userLogin); + deactivate(child, parentActiveRule.getRule(), userName); } getSession().commit(); } @@ -201,7 +202,7 @@ public class ProfilesManager extends BaseDao { return false; } - public void revert(int profileId, int activeRuleId, String userLogin) { + public void revert(int profileId, int activeRuleId, String userName) { RulesProfile profile = getSession().getEntity(RulesProfile.class, profileId); ActiveRule oldActiveRule = getSession().getEntity(ActiveRule.class, activeRuleId); if (oldActiveRule != null && oldActiveRule.doesOverride()) { @@ -214,10 +215,10 @@ public class ProfilesManager extends BaseDao { getSession().saveWithoutFlush(newActiveRule); // Compute change - ruleChanged(profile, oldActiveRule, newActiveRule, userLogin); + ruleChanged(profile, oldActiveRule, newActiveRule, userName); for (RulesProfile child : getChildren(profile)) { - activateOrChange(child, newActiveRule, userLogin); + activateOrChange(child, newActiveRule, userName); } getSession().commit(); @@ -235,9 +236,9 @@ public class ProfilesManager extends BaseDao { /** * Deal with creation of ActiveRuleChange item when a rule param is changed on a profile */ - private void ruleParamChanged(RulesProfile profile, Rule rule, String paramKey, String oldValue, String newValue, String userLogin) { + private void ruleParamChanged(RulesProfile profile, Rule rule, String paramKey, String oldValue, String newValue, String userName) { incrementProfileVersionIfNeeded(profile); - ActiveRuleChange rc = new ActiveRuleChange(userLogin, profile, rule); + ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule); if (!StringUtils.equals(oldValue, newValue)) { rc.setParameterChange(paramKey, oldValue, newValue); getSession().saveWithoutFlush(rc); @@ -247,10 +248,10 @@ public class ProfilesManager extends BaseDao { /** * Deal with creation of ActiveRuleChange item when a rule severity is changed on a profile */ - private void ruleSeverityChanged(RulesProfile profile, Rule rule, RulePriority oldSeverity, RulePriority newSeverity, String userLogin) { + private void ruleSeverityChanged(RulesProfile profile, Rule rule, RulePriority oldSeverity, RulePriority newSeverity, String userName) { incrementProfileVersionIfNeeded(profile); - ActiveRuleChange rc = new ActiveRuleChange(userLogin, profile, rule); - if (oldSeverity != newSeverity) { + ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule); + if (!ObjectUtils.equals(oldSeverity, newSeverity)) { rc.setOldSeverity(oldSeverity); rc.setNewSeverity(newSeverity); getSession().saveWithoutFlush(rc); @@ -260,9 +261,9 @@ public class ProfilesManager extends BaseDao { /** * Deal with creation of ActiveRuleChange item when a rule is changed (severity and/or param(s)) on a profile */ - private void ruleChanged(RulesProfile profile, ActiveRule oldActiveRule, ActiveRule newActiveRule, String userLogin) { + private void ruleChanged(RulesProfile profile, ActiveRule oldActiveRule, ActiveRule newActiveRule, String userName) { incrementProfileVersionIfNeeded(profile); - ActiveRuleChange rc = new ActiveRuleChange(userLogin, profile, newActiveRule.getRule()); + ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule()); if (oldActiveRule.getSeverity() != newActiveRule.getSeverity()) { rc.setOldSeverity(oldActiveRule.getSeverity()); @@ -284,9 +285,9 @@ public class ProfilesManager extends BaseDao { /** * Deal with creation of ActiveRuleChange item when a rule is enabled on a profile */ - private void ruleEnabled(RulesProfile profile, ActiveRule newActiveRule, String userLogin) { + private void ruleEnabled(RulesProfile profile, ActiveRule newActiveRule, String userName) { incrementProfileVersionIfNeeded(profile); - ActiveRuleChange rc = new ActiveRuleChange(userLogin, profile, newActiveRule.getRule()); + ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule()); rc.setEnabled(true); rc.setNewSeverity(newActiveRule.getSeverity()); if (newActiveRule.getRule().getParams() != null) { @@ -303,9 +304,9 @@ public class ProfilesManager extends BaseDao { /** * Deal with creation of ActiveRuleChange item when a rule is disabled on a profile */ - private void ruleDisabled(RulesProfile profile, ActiveRule disabledRule, String userLogin) { + private void ruleDisabled(RulesProfile profile, ActiveRule disabledRule, String userName) { incrementProfileVersionIfNeeded(profile); - ActiveRuleChange rc = new ActiveRuleChange(userLogin, profile, disabledRule.getRule()); + ActiveRuleChange rc = new ActiveRuleChange(userName, profile, disabledRule.getRule()); rc.setEnabled(false); rc.setOldSeverity(disabledRule.getSeverity()); if (disabledRule.getRule().getParams() != null) { @@ -319,7 +320,7 @@ public class ProfilesManager extends BaseDao { getSession().saveWithoutFlush(rc); } - private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule, String userLogin) { + private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule, String userName) { ActiveRule oldActiveRule = profile.getActiveRule(parentActiveRule.getRule()); if (oldActiveRule != null) { if (oldActiveRule.isInherited()) { @@ -337,21 +338,21 @@ public class ProfilesManager extends BaseDao { getSession().saveWithoutFlush(newActiveRule); if (oldActiveRule != null) { - ruleChanged(profile, oldActiveRule, newActiveRule, userLogin); + ruleChanged(profile, oldActiveRule, newActiveRule, userName); } else { - ruleEnabled(profile, newActiveRule, userLogin); + ruleEnabled(profile, newActiveRule, userName); } for (RulesProfile child : getChildren(profile)) { - activateOrChange(child, newActiveRule, userLogin); + activateOrChange(child, newActiveRule, userName); } } - private void deactivate(RulesProfile profile, Rule rule, String userLogin) { + private void deactivate(RulesProfile profile, Rule rule, String userName) { ActiveRule activeRule = profile.getActiveRule(rule); if (activeRule != null) { if (activeRule.isInherited()) { - ruleDisabled(profile, activeRule, userLogin); + ruleDisabled(profile, activeRule, userName); removeActiveRule(profile, activeRule); } else { activeRule.setInheritance(null); @@ -360,7 +361,7 @@ public class ProfilesManager extends BaseDao { } for (RulesProfile child : getChildren(profile)) { - deactivate(child, rule, userLogin); + deactivate(child, rule, userName); } } } 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 8b8cf857bbb..3d0a621fec8 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 @@ -229,29 +229,29 @@ public final class JRubyFacade { getProfilesManager().deleteProfile((int) profileId); } - public ValidationMessages changeParentProfile(int profileId, String parentName, String userLogin) { - return getProfilesManager().changeParentProfile(profileId, parentName, userLogin); + public ValidationMessages changeParentProfile(int profileId, String parentName, String userName) { + return getProfilesManager().changeParentProfile(profileId, parentName, userName); } - public void ruleActivated(int parentProfileId, int activeRuleId, String userLogin) { - getProfilesManager().activated(parentProfileId, activeRuleId, userLogin); + public void ruleActivated(int parentProfileId, int activeRuleId, String userName) { + getProfilesManager().activated(parentProfileId, activeRuleId, userName); } - public void ruleParamChanged(int parentProfileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userLogin) { - getProfilesManager().ruleParamChanged(parentProfileId, activeRuleId, paramKey, oldValue, newValue, userLogin); + public void ruleParamChanged(int parentProfileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) { + getProfilesManager().ruleParamChanged(parentProfileId, activeRuleId, paramKey, oldValue, newValue, userName); } - public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userLogin) { + public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) { getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId], - RulePriority.values()[newSeverityId], userLogin); + RulePriority.values()[newSeverityId], userName); } - public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userLogin) { - getProfilesManager().deactivated(parentProfileId, deactivatedRuleId, userLogin); + public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) { + getProfilesManager().deactivated(parentProfileId, deactivatedRuleId, userName); } - public void revertRule(int profileId, int activeRuleId, String userLogin) { - getProfilesManager().revert(profileId, activeRuleId, userLogin); + public void revertRule(int profileId, int activeRuleId, String userName) { + getProfilesManager().revert(profileId, activeRuleId, userName); } public List