private final List<ProfileImporter> importers;
private final PreviewCache dryRunCache;
private final RuleRegistry ruleRegistry;
- private final ProfileRules profileRules;
private final ProfilesManager profilesManager;
private final System2 system;
public QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao,
PreviewCache dryRunCache, RuleRegistry ruleRegistry, ProfilesManager profilesManager, ProfileRules profileRules) {
this(myBatis, dao, activeRuleDao, ruleDao, propertiesDao, Lists.<ProfileImporter>newArrayList(), dryRunCache, ruleRegistry,
- profilesManager, profileRules, System2.INSTANCE);
+ profilesManager, System2.INSTANCE);
}
public QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao,
List<ProfileImporter> importers, PreviewCache dryRunCache, RuleRegistry ruleRegistry,
ProfilesManager profilesManager, ProfileRules profileRules) {
this(myBatis, dao, activeRuleDao, ruleDao, propertiesDao, Lists.<ProfileImporter>newArrayList(), dryRunCache, ruleRegistry,
- profilesManager, profileRules, System2.INSTANCE);
+ profilesManager, System2.INSTANCE);
}
@VisibleForTesting
QProfileOperations(MyBatis myBatis, QualityProfileDao dao, ActiveRuleDao activeRuleDao, RuleDao ruleDao, PropertiesDao propertiesDao,
List<ProfileImporter> importers, PreviewCache dryRunCache, RuleRegistry ruleRegistry,
- ProfilesManager profilesManager, ProfileRules profileRules, System2 system) {
+ ProfilesManager profilesManager, System2 system) {
this.myBatis = myBatis;
this.dao = dao;
this.activeRuleDao = activeRuleDao;
this.dryRunCache = dryRunCache;
this.ruleRegistry = ruleRegistry;
this.profilesManager = profilesManager;
- this.profileRules = profileRules;
this.system = system;
}
// ACTIVE RULES
// bulk activate all
// bulk deactivate all
- // update note on an active rule (only E/S indexing)
- // delete note on an active rule (only E/S indexing)
// extends extension of a rule (only E/S indexing)
// revert modification on active rule with inheritance
// active rule parameter validation (only Integer types are checked)
return rules.getFromActiveRuleId(activeRule.getId());
}
+ // RULES
+
public QProfileRule updateRuleNote(int activeRuleId, int ruleId, String note) {
RuleDto rule = findRuleNotNull(ruleId);
String sanitizedNote = Strings.emptyToNull(note);
return rules.getFromActiveRuleId(activeRule.getId());
}
+ @CheckForNull
+ public QProfileRule rule(int ruleId) {
+// "".indexOf();
+ return rules.getFromRuleId(ruleId);
+ }
+
//
// Quality profile validation
#
def new
# form to duplicate a rule
- access_denied unless has_role?(:profileadmin)
require_parameters :id, :rule_id
- @profile = Profile.find(params[:id].to_i)
- add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language), {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}}
+ @profile = Internal.quality_profiles.profile(params[:id].to_i)
+ add_breadcrumbs ProfilesController::root_breadcrumb, Api::Utils.language_name(@profile.language),
+ {:name => @profile.name, :url => {:controller => 'new_rules_configuration', :action => 'index', :id => @profile.id}}
- @rule = Rule.find(params[:rule_id])
+ @rule = Internal.quality_profiles.rule(params[:rule_id].to_i)
end
#
end
def param_value_input(rule, parameter, value, options = {})
- type=type_with_compatibility(parameter.type)
+ type = type_with_compatibility(parameter.type().to_s)
name = options[:name] || 'value'
- property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id}#{parameter.key}", :size => options[:size] }.update(options)
+ property_input_field name, type, value, 'WIDGET', {:id => "#{rule.id().to_s}#{parameter.key().to_s}", :size => options[:size] }.update(options)
end
def is_set(type)
</select>
</td>
</tr>
- <% @rule.parameters.sort{|x,y| x.name <=> y.name}.each do |parameter| %>
- <tr>
- <td width="1%" nowrap><%= parameter.name %>:</td>
- <td class="sep"> </td>
- <td>
- <%= param_value_input(parameter, "", {:name => "rule_param[#{h parameter.name}]", :size => '80x10'}) -%>
- <span class="small"><%= h parameter.description %></span>
- </td>
- </tr>
+ <% if @rule.params && @rule.params.to_a.size > 0 %>
+ <% @rule.params.to_a.sort{|x,y| x.key() <=> y.key()}.each do |parameter| %>
+ <% puts "### parameter : " + parameter.inspect %>
+ <tr>
+ <td width="1%" nowrap><%= parameter.key() %>:</td>
+ <td class="sep"> </td>
+ <td>
+ <%= param_value_input(@rule, parameter, "", {:name => "rule_param[#{h parameter.key()}]", :size => '80x10'}) -%>
+ <span class="small"><%= h parameter.description() %></span>
+ </td>
+ </tr>
+ <% end %>
<% end %>
<tr>
<td width="1%" nowrap style="vertical-align: top"><%= message('description') -%>:</td>
import org.sonar.server.configuration.ProfilesManager;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
-import org.sonar.server.rule.ProfileRules;
import org.sonar.server.rule.RuleRegistry;
import org.sonar.server.user.MockUserSession;
import org.sonar.server.user.UserSession;
@Mock
RuleRegistry ruleRegistry;
- @Mock
- ProfileRules profileRules;
-
@Mock
ProfilesManager profilesManager;
}).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(SqlSession.class));
operations = new QProfileOperations(myBatis, qualityProfileDao, activeRuleDao, ruleDao, propertiesDao, importers, dryRunCache, ruleRegistry, profilesManager,
- profileRules, system);
+ system);
}
@Test
QualityProfileDto qualityProfile = new QualityProfileDto().setId(1).setName("My profile").setLanguage("java");
RuleDto rule = new RuleDto().setId(10).setRepositoryKey("squid").setRuleKey("AvoidCycle");
when(ruleDao.selectParameters(eq(10), eq(session))).thenReturn(newArrayList(new RuleParamDto().setId(20).setName("max").setDefaultValue("10")));
- when(profileRules.getFromActiveRuleId(anyInt())).thenReturn(mock(QProfileRule.class));
final int idActiveRuleToUpdate = 42;
final int idActiveRuleToDelete = 24;
RuleInheritanceActions inheritanceActions = new RuleInheritanceActions()
Rule rule = Rule.create().setRepositoryKey("squid").setKey("AvoidCycle");
rule.setId(10);
ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1);
- when(profileRules.getFromActiveRuleId(anyInt())).thenReturn(mock(QProfileRule.class));
when(profilesManager.ruleSeverityChanged(eq(1), eq(5), eq(RulePriority.MINOR), eq(RulePriority.MAJOR), eq("Nicolas"))).thenReturn(new RuleInheritanceActions());
operations.updateSeverity(qualityProfile, activeRule, Severity.MAJOR, authorizedUserSession);
public void deactivate_rule() throws Exception {
ActiveRuleDto activeRule = new ActiveRuleDto().setId(5).setProfileId(1).setRuleId(10).setSeverity(1);
when(activeRuleDao.selectByProfileAndRule(1, 10)).thenReturn(activeRule);
- when(profileRules.getFromRuleId(anyInt())).thenReturn(mock(QProfileRule.class));
when(profilesManager.deactivated(eq(1), anyInt(), eq("Nicolas"))).thenReturn(new RuleInheritanceActions());
operations.deactivateRule(activeRule, authorizedUserSession);
when(qualityProfileDao.selectById(1)).thenReturn(qualityProfile);
QProfileRule rule = mock(QProfileRule.class);
when(rule.id()).thenReturn(10);
- when(rules.getFromRuleId(10)).thenReturn(null);
try {
qProfiles.activateRule(1, 10, Severity.BLOCKER);
verify(service).deleteRuleNote(eq(rule), any(UserSession.class));
}
+ @Test
+ public void get_rule_from_id() throws Exception {
+ qProfiles.rule(10);
+
+ verify(rules).getFromRuleId(10);
+ }
+
}