}
}
- private synchronized boolean shouldTrackChanges(RulesProfile profile) {
- return profile.getVersion() > 1 || profile.getVersion() == 1 && profile.getUsed();
- }
-
/**
* 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 userName) {
- if (shouldTrackChanges(profile)) {
- incrementProfileVersionIfNeeded(profile);
- ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule);
- if (!StringUtils.equals(oldValue, newValue)) {
- rc.setParameterChange(paramKey, oldValue, newValue);
- getSession().saveWithoutFlush(rc);
- }
+ incrementProfileVersionIfNeeded(profile);
+ ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule);
+ if (!StringUtils.equals(oldValue, newValue)) {
+ rc.setParameterChange(paramKey, oldValue, newValue);
+ getSession().saveWithoutFlush(rc);
}
}
* 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 userName) {
- if (shouldTrackChanges(profile)) {
- incrementProfileVersionIfNeeded(profile);
- ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule);
- if (!ObjectUtils.equals(oldSeverity, newSeverity)) {
- rc.setOldSeverity(oldSeverity);
- rc.setNewSeverity(newSeverity);
- getSession().saveWithoutFlush(rc);
- }
+ incrementProfileVersionIfNeeded(profile);
+ ActiveRuleChange rc = new ActiveRuleChange(userName, profile, rule);
+ if (!ObjectUtils.equals(oldSeverity, newSeverity)) {
+ rc.setOldSeverity(oldSeverity);
+ rc.setNewSeverity(newSeverity);
+ getSession().saveWithoutFlush(rc);
}
}
* 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 userName) {
- if (shouldTrackChanges(profile)) {
- incrementProfileVersionIfNeeded(profile);
- ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());
+ incrementProfileVersionIfNeeded(profile);
+ ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());
- if (oldActiveRule.getSeverity() != newActiveRule.getSeverity()) {
- rc.setOldSeverity(oldActiveRule.getSeverity());
- rc.setNewSeverity(newActiveRule.getSeverity());
- }
- if (oldActiveRule.getRule().getParams() != null) {
- for (RuleParam p : oldActiveRule.getRule().getParams()) {
- String oldParam = oldActiveRule.getParameter(p.getKey());
- String newParam = newActiveRule.getParameter(p.getKey());
- if (!StringUtils.equals(oldParam, newParam)) {
- rc.setParameterChange(p.getKey(), oldParam, newParam);
- }
+ if (oldActiveRule.getSeverity() != newActiveRule.getSeverity()) {
+ rc.setOldSeverity(oldActiveRule.getSeverity());
+ rc.setNewSeverity(newActiveRule.getSeverity());
+ }
+ if (oldActiveRule.getRule().getParams() != null) {
+ for (RuleParam p : oldActiveRule.getRule().getParams()) {
+ String oldParam = oldActiveRule.getParameter(p.getKey());
+ String newParam = newActiveRule.getParameter(p.getKey());
+ if (!StringUtils.equals(oldParam, newParam)) {
+ rc.setParameterChange(p.getKey(), oldParam, newParam);
}
}
-
- getSession().saveWithoutFlush(rc);
}
+
+ getSession().saveWithoutFlush(rc);
}
/**
* Deal with creation of ActiveRuleChange item when a rule is enabled on a profile
*/
private void ruleEnabled(RulesProfile profile, ActiveRule newActiveRule, String userName) {
- if (shouldTrackChanges(profile)) {
- incrementProfileVersionIfNeeded(profile);
- ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());
- rc.setEnabled(true);
- rc.setNewSeverity(newActiveRule.getSeverity());
- if (newActiveRule.getRule().getParams() != null) {
- for (RuleParam p : newActiveRule.getRule().getParams()) {
- String newParam = newActiveRule.getParameter(p.getKey());
- if (newParam != null) {
- rc.setParameterChange(p.getKey(), null, newParam);
- }
+ incrementProfileVersionIfNeeded(profile);
+ ActiveRuleChange rc = new ActiveRuleChange(userName, profile, newActiveRule.getRule());
+ rc.setEnabled(true);
+ rc.setNewSeverity(newActiveRule.getSeverity());
+ if (newActiveRule.getRule().getParams() != null) {
+ for (RuleParam p : newActiveRule.getRule().getParams()) {
+ String newParam = newActiveRule.getParameter(p.getKey());
+ if (newParam != null) {
+ rc.setParameterChange(p.getKey(), null, newParam);
}
}
- getSession().saveWithoutFlush(rc);
}
+ getSession().saveWithoutFlush(rc);
}
/**
* Deal with creation of ActiveRuleChange item when a rule is disabled on a profile
*/
private void ruleDisabled(RulesProfile profile, ActiveRule disabledRule, String userName) {
- if (shouldTrackChanges(profile)) {
- incrementProfileVersionIfNeeded(profile);
- ActiveRuleChange rc = new ActiveRuleChange(userName, profile, disabledRule.getRule());
- rc.setEnabled(false);
- rc.setOldSeverity(disabledRule.getSeverity());
- if (disabledRule.getRule().getParams() != null) {
- for (RuleParam p : disabledRule.getRule().getParams()) {
- String oldParam = disabledRule.getParameter(p.getKey());
- if (oldParam != null) {
- rc.setParameterChange(p.getKey(), oldParam, null);
- }
+ incrementProfileVersionIfNeeded(profile);
+ ActiveRuleChange rc = new ActiveRuleChange(userName, profile, disabledRule.getRule());
+ rc.setEnabled(false);
+ rc.setOldSeverity(disabledRule.getSeverity());
+ if (disabledRule.getRule().getParams() != null) {
+ for (RuleParam p : disabledRule.getRule().getParams()) {
+ String oldParam = disabledRule.getParameter(p.getKey());
+ if (oldParam != null) {
+ rc.setParameterChange(p.getKey(), oldParam, null);
}
}
- getSession().saveWithoutFlush(rc);
}
+ getSession().saveWithoutFlush(rc);
}
private void activateOrChange(RulesProfile profile, ActiveRule parentActiveRule, String userName) {
private List<RulesProfile> getChildren(RulesProfile parent) {
return getSession().getResults(RulesProfile.class,
- "language", parent.getLanguage(),
- "parentName", parent.getName());
+ "language", parent.getLanguage(),
+ "parentName", parent.getName());
}
private void removeActiveRule(RulesProfile profile, ActiveRule activeRule) {
RulesProfile getProfile(String language, String name) {
return getSession().getSingleResult(RulesProfile.class,
- "language", language,
- "name", name);
+ "language", language,
+ "name", name);
}
RulesProfile getParentProfile(RulesProfile profile) {
@profile = Profile.find(params[:id])
versions = ActiveRuleChange.all(:select => 'profile_version, MAX(change_date) AS change_date', :conditions => ['profile_id=?', @profile.id], :group => 'profile_version')
+ # Add false change version 1 when no change have been made in profile version 1
+ versions << ActiveRuleChange.new(:profile_version => 1, :profile_id => @profile.id) unless versions.find {|version| version.profile_version == 1}
versions.sort! { |a, b| b.profile_version <=> a.profile_version }
- unless versions.empty?
+ # SONAR-2986
+ # Display changelog only from profile version 2
+ if @profile.version > 1
last_version = versions[0].profile_version
if params[:since].blank?
@since_version = last_version - 1
end
@changes = ActiveRuleChange.all(:conditions => ['profile_id=? and ?<profile_version and profile_version<=?', @profile.id, @since_version, @to_version], :order => 'id desc')
- @select_versions = versions.map { |u| [message(u.profile_version == last_version ? 'quality_profiles.last_version_x_with_date' : 'quality_profiles.version_x_with_date',
- :params => [u.profile_version.to_s, l(u.change_date)]), u.profile_version] } |
- [[message('quality_profiles.version_1'), 0]]
+ @select_versions = versions.map do |u|
+ if u.change_date
+ message = message(u.profile_version == last_version ? 'quality_profiles.last_version_x_with_date' : 'quality_profiles.version_x_with_date',
+ :params => [u.profile_version.to_s, l(u.change_date)])
+ else
+ # Specific case when no change have been made in profile version 1 -> no date will be displayed
+ message = message('quality_profiles.version_x', :params => u.profile_version)
+ end
+ [message, u.profile_version]
+ end
end
set_profile_breadcrumbs