def readable_type(type)
return "Set of string (, as delimiter)" if type == PARAM_TYPE_STRING_LIST
- return "Number" if type == PARAM_TYPE_INTEGER
+ return "Number" if type_with_compatibility(type) == PropertyType::TYPE_INTEGER
return "Set of number (, as delimiter)" if type == PARAM_TYPE_INTEGER_LIST
return "Regular expression" if type == PARAM_TYPE_REGEXP
return "Set of values (, as delimiter)" if is_set(type)
def is_set(type)
type.at(1) == "[" && type.ends_with?("]")
end
+
+ def validate_rule_param(attribute, param_type, errors, value)
+ return if attribute.nil? or attribute.length == 0
+
+ type=type_with_compatibility(param_type)
+
+ if is_set_type
+ allowed_tokens = get_allowed_tokens
+ attribute.split(',').each do |provided_token|
+ if !allowed_tokens.include?(provided_token)
+ errors.add("#{value}", "'#{provided_token}' kust be one of : " + allowed_tokens.join(', '))
+ end
+ end
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER_LIST
+ attribute.split(',').each do |n|
+ if !Api::Utils.is_integer?(n)
+ errors.add("#{value}", "'#{n}' must be an integer.")
+ return
+ end
+ end
+ elsif param_type == RulesConfigurationHelper::PARAM_TYPE_REGEXP
+ if !Api::Utils.is_regexp?(attribute)
+ errors.add("#{value}", "'#{attribute}' must be a regular expression")
+ end
+ elsif type == PropertyType::TYPE_INTEGER
+ if !Api::Utils.is_integer?(attribute)
+ errors.add("#{value}", "'#{attribute}' must be an integer.")
+ end
+ elsif type == PropertyType::TYPE_BOOLEAN
+ if !Api::Utils.is_boolean?(attribute)
+ errors.add("#{value}", "'#{attribute}' must be one of : true,false")
+ end
+ end
+ end
end
s.to_s =~ /\A[+-]?\d+\Z/
end
+ def self.is_boolean?(s)
+ s == 'true' || s == 'false'
+ end
+
+ def self.is_regexp?(s)
+ begin
+ Regexp.new(S)
+ true
+ rescue
+ false
+ end
+ end
+
def self.markdown_to_html(markdown)
markdown ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(markdown)) : ''
end
end
def validate_value(attribute, errors, value)
- return if attribute.nil? or attribute.length == 0
- if is_set_type
- provided_tokens = attribute.split(",")
- allowed_tokens = get_allowed_tokens
- provided_tokens.each do |provided_token|
- if !allowed_tokens.include?(provided_token)
- errors.add("#{value}", "'#{provided_token}' kust be one of : " + allowed_tokens.join(", "))
- end
- end
- elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER
- if !Api::Utils.is_integer?(attribute)
- errors.add("#{value}", "'#{attribute}' must be an integer.")
- end
- elsif param_type == RulesConfigurationHelper::PARAM_TYPE_INTEGER_LIST
- provided_numbers = attribute.split(",")
- provided_numbers.each do |provided_number|
- if !Api::Utils.is_integer?(provided_number)
- errors.add("#{value}", "'#{provided_number}' must be an integer.")
- return
- end
- end
- elsif param_type == RulesConfigurationHelper::PARAM_TYPE_BOOLEAN
- if attribute != "true" && attribute != "false"
- errors.add("#{value}", "'#{attribute}' must be one of : true,false")
- end
- elsif param_type == RulesConfigurationHelper::PARAM_TYPE_REGEXP
- begin
- Regexp.new(attribute)
- rescue
- errors.add("#{value}", "'#{attribute}' must be a regular expression")
- end
- end
+ validate_rule_param(attribute, param_type, errors, value)
end
def to_hash_json(active_rule)
<td class="form-val-cell">
<%= form_remote_tag :url => {:action => :update_param, :id => active_param_id, :profile_id => profile.id, :param_id => parameter.id, :active_rule_id => active_rule_id},
- :update => {:success => "rule_#{rule.id}", :failure => "error_#{rule.id}"},
+ :update => {:success => "rule_#{rule.id}", :failure => "error_#{parameter.id}"},
:loading => "$('param_loading_#{parameter.id}').show();",
:complete => "$('desc_#{rule.id}').show();",
- :failure => "$('error_#{rule.id}').show();$('param_loading_#{parameter.id}').hide();",
+ :failure => "$('error_#{parameter.id}').show();$('param_loading_#{parameter.id}').hide();",
:html => {:name => "form-#{u parameter.name}"} %>
- <div id="error_<%= rule.id -%>" class="error" style="display: none"></div>
+ <div id="error_<%= parameter.id -%>" class="error" style="display: none"></div>
<span id="<%= span_id -%>"><%= param_value_input(parameter, param_value, :disabled => read_only) -%></span>