]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4501 Make properties (sub)categories case insensitives
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 16 Jul 2013 13:05:53 +0000 (15:05 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 16 Jul 2013 13:13:51 +0000 (15:13 +0200)
13 files changed:
plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinitions.java
sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionsTest.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/application_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/helpers/settings_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_properties.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/settings/_settings.html.erb

index 8badcd35be4c81654930e0d27f44e6a5feb1e6f1..729b49aced07e68cd6095787eed4cc3c02c56398 100644 (file)
@@ -1551,9 +1551,9 @@ email_configuration.test.email_was_sent_to_x=Email was sent to {0}
 # LICENSES & SERVER KEY CONFIGURATION
 #
 #------------------------------------------------------------------------------
-property.category.Licenses=Licenses
-property.category.Licenses.description=In case of any issue or question about licenses, please send an email to contact@sonarsource.com.
-property.category.Licenses.server_id=Server ID
+property.category.licenses=Licenses
+property.category.licenses.description=In case of any issue or question about licenses, please send an email to contact@sonarsource.com.
+property.category.licenses.server_id=Server ID
 server_id_configuration.generate_button=Generate ID
 server_id_configuration.generating_button=Generating ID...
 server_id_configuration.bad_key=The ID is not valid anymore. Please check the organisation and the IP address.
index 084cabc0d63cef1b1ef76749d3db673320985ece..027b5d9a4e89ed2fa981cd9ce004dcbc3c28c277 100644 (file)
@@ -72,6 +72,11 @@ public interface CoreProperties {
    */
   String CATEGORY_EXCLUSIONS = "exclusions";
 
+  /**
+   * @since 3.7
+   */
+  String CATEGORY_LICENSES = "licenses";
+
   /* Global settings */
   String SONAR_HOME = "SONAR_HOME";
   String PROJECT_BRANCH_PROPERTY = "sonar.branch";
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Category.java
new file mode 100644 (file)
index 0000000..ddb8ff3
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.config;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Locale;
+
+/**
+ * @since 3.7
+ */
+public class Category {
+
+  private final String originalKey;
+  private final boolean special;
+
+  public Category(String originalKey) {
+    this(originalKey, false);
+  }
+
+  Category(String originalKey, boolean special) {
+    this.originalKey = originalKey;
+    this.special = special;
+  }
+
+  public String originalKey() {
+    return originalKey;
+  }
+
+  public String key() {
+    return StringUtils.lowerCase(originalKey, Locale.ENGLISH);
+  }
+
+  public boolean isSpecial() {
+    return special;
+  }
+
+  @Override
+  public int hashCode() {
+    return key().hashCode();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (!(obj instanceof Category)) {
+      return false;
+    }
+    return StringUtils.equalsIgnoreCase(((Category) obj).originalKey, this.originalKey);
+  }
+
+  @Override
+  public String toString() {
+    return this.originalKey;
+  }
+
+}
index b729e1064afec90dcba80c4cbb7674bbeb28db82..94edae487ffe1099035cc24d776dc99124be098b 100644 (file)
@@ -23,6 +23,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Maps;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.Properties;
 import org.sonar.api.Property;
 import org.sonar.api.ServerComponent;
@@ -44,8 +45,8 @@ import java.util.Map;
 public final class PropertyDefinitions implements BatchComponent, ServerComponent {
 
   private final Map<String, PropertyDefinition> definitions = Maps.newHashMap();
-  private final Map<String, String> categories = Maps.newHashMap();
-  private final Map<String, String> subcategories = Maps.newHashMap();
+  private final Map<String, Category> categories = Maps.newHashMap();
+  private final Map<String, SubCategory> subcategories = Maps.newHashMap();
 
   // deprecated key -> new key
   private final Map<String, String> deprecatedKeys = Maps.newHashMap();
@@ -107,8 +108,9 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
     if (!definitions.containsKey(definition.key())) {
       definitions.put(definition.key(), definition);
       String category = StringUtils.defaultIfBlank(definition.category(), defaultCategory);
-      categories.put(definition.key(), category);
-      subcategories.put(definition.key(), StringUtils.defaultIfBlank(definition.subCategory(), category));
+      categories.put(definition.key(), new Category(category));
+      String subcategory = StringUtils.defaultIfBlank(definition.subCategory(), category);
+      subcategories.put(definition.key(), new SubCategory(subcategory));
       if (!Strings.isNullOrEmpty(definition.deprecatedKey()) && !definition.deprecatedKey().equals(definition.key())) {
         deprecatedKeys.put(definition.deprecatedKey(), definition.key());
       }
@@ -130,7 +132,9 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
 
   /**
    * @since 3.6
+   * @deprecated since 3.7 use {@link #propertiesByCategory(String)}
    */
+  @Deprecated
   public Map<String, Map<String, Collection<PropertyDefinition>>> getPropertiesByCategory(@Nullable String qualifier) {
     Map<String, Map<String, Collection<PropertyDefinition>>> byCategory = new HashMap<String, Map<String, Collection<PropertyDefinition>>>();
 
@@ -151,10 +155,45 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
     return byCategory;
   }
 
+  /**
+   * @since 3.6
+   * @deprecated since 3.7 use {@link #propertiesByCategory(String)}
+   */
+  @Deprecated
   public Map<String, Map<String, Collection<PropertyDefinition>>> getPropertiesByCategory() {
     return getPropertiesByCategory(null);
   }
 
+  /**
+   * @since 3.7
+   */
+  public Map<Category, Map<SubCategory, Collection<PropertyDefinition>>> propertiesByCategory(@Nullable String qualifier) {
+    Map<Category, Map<SubCategory, Collection<PropertyDefinition>>> byCategory = new HashMap<Category, Map<SubCategory, Collection<PropertyDefinition>>>();
+    if (qualifier == null) {
+      // Special categories on global page
+      byCategory.put(new Category("email", true), new HashMap<SubCategory, Collection<PropertyDefinition>>());
+      byCategory.put(new Category("encryption", true), new HashMap<SubCategory, Collection<PropertyDefinition>>());
+      HashMap<SubCategory, Collection<PropertyDefinition>> licenseSubCategories = new HashMap<SubCategory, Collection<PropertyDefinition>>();
+      licenseSubCategories.put(new SubCategory("server_id", true), new ArrayList<PropertyDefinition>());
+      byCategory.put(new Category(CoreProperties.CATEGORY_LICENSES, false), licenseSubCategories);
+    }
+    for (PropertyDefinition definition : getAll()) {
+      if (qualifier == null ? definition.global() : definition.qualifiers().contains(qualifier)) {
+        Category category = categories.get(definition.key());
+        if (!byCategory.containsKey(category)) {
+          byCategory.put(category, new HashMap<SubCategory, Collection<PropertyDefinition>>());
+        }
+        SubCategory subCategory = subcategories.get(definition.key());
+        if (!byCategory.get(category).containsKey(subCategory)) {
+          byCategory.get(category).put(subCategory, new ArrayList<PropertyDefinition>());
+        }
+        byCategory.get(category).get(subCategory).add(definition);
+      }
+    }
+
+    return byCategory;
+  }
+
   public String getDefaultValue(String key) {
     PropertyDefinition def = get(key);
     if (def == null) {
@@ -164,11 +203,11 @@ public final class PropertyDefinitions implements BatchComponent, ServerComponen
   }
 
   public String getCategory(String key) {
-    return categories.get(validKey(key));
+    return categories.get(validKey(key)).toString();
   }
 
   public String getSubCategory(String key) {
-    return subcategories.get(validKey(key));
+    return subcategories.get(validKey(key)).toString();
   }
 
   public String getCategory(Property prop) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/SubCategory.java
new file mode 100644 (file)
index 0000000..cd90b20
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.config;
+
+/**
+ * @since 3.7
+ */
+public class SubCategory extends Category {
+
+  public SubCategory(String originalKey) {
+    super(originalKey);
+  }
+
+  SubCategory(String originalKey, boolean special) {
+    super(originalKey, special);
+  }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java
new file mode 100644 (file)
index 0000000..e8ee207
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.api.config;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class CategoryTest {
+
+  @Test
+  public void category_key_is_case_insentive() {
+    assertThat(new Category("Licenses")).isEqualTo(new Category("licenses"));
+  }
+
+  @Test
+  public void should_preserve_original_key() {
+    assertThat(new Category("Licenses").originalKey()).isEqualTo("Licenses");
+  }
+}
index ed794b4dc8cba6a41c2c19a7174c79500df98f69..9bc2eace66b3f5bdeff2afc87c1fd9f721fbfd89 100644 (file)
@@ -34,10 +34,10 @@ public class PropertyDefinitionsTest {
   @Test
   public void should_build_with_predefined_list_of_definitions() {
     List<PropertyDefinition> list = Arrays.asList(
-      PropertyDefinition.builder("foo").name("Foo").build(),
-      PropertyDefinition.builder("one").name("One").build(),
-      PropertyDefinition.builder("two").name("Two").defaultValue("2").build()
-    );
+        PropertyDefinition.builder("foo").name("Foo").build(),
+        PropertyDefinition.builder("one").name("One").build(),
+        PropertyDefinition.builder("two").name("Two").defaultValue("2").build()
+        );
     PropertyDefinitions def = new PropertyDefinitions(list);
 
     assertProperties(def);
@@ -46,9 +46,9 @@ public class PropertyDefinitionsTest {
   @Test
   public void should_inspect_plugin_objects() {
     PropertyDefinitions def = new PropertyDefinitions(
-      PropertyDefinition.builder("foo").name("Foo").build(),
-      PropertyDefinition.builder("one").name("One").build(),
-      PropertyDefinition.builder("two").name("Two").defaultValue("2").build()
+        PropertyDefinition.builder("foo").name("Foo").build(),
+        PropertyDefinition.builder("one").name("One").build(),
+        PropertyDefinition.builder("two").name("Two").defaultValue("2").build()
         );
 
     assertProperties(def);
@@ -71,8 +71,8 @@ public class PropertyDefinitionsTest {
   @Test
   public void test_categories() {
     PropertyDefinitions def = new PropertyDefinitions(
-      PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(),
-      PropertyDefinition.builder("noCateg").name("No categ").build()
+        PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(),
+        PropertyDefinition.builder("noCateg").name("No categ").build()
         );
 
     assertThat(def.getCategory("inCateg")).isEqualTo("categ");
@@ -105,15 +105,25 @@ public class PropertyDefinitionsTest {
     assertThat(def.getCategory("noCateg")).isEqualTo("default");
   }
 
+  @Test
+  public void should_return_special_categories() {
+    PropertyDefinitions def = new PropertyDefinitions();
+
+    assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses"));
+    assertThat(def.propertiesByCategory(null).keySet().iterator().next().isSpecial()).isTrue();
+    assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet()).containsOnly(new SubCategory("server_id"));
+    assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet().iterator().next().isSpecial()).isTrue();
+  }
+
   @Test
   public void should_group_by_category() {
     PropertyDefinitions def = new PropertyDefinitions(
-      PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(),
-      PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(),
-      PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(),
-      PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(),
-      PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(),
-      PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build()
+        PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").build(),
+        PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").build(),
+        PropertyDefinition.builder("global3").name("Global3").category("catGlobal2").build(),
+        PropertyDefinition.builder("project").name("Project").category("catProject").onlyOnQualifiers(Qualifiers.PROJECT).build(),
+        PropertyDefinition.builder("module").name("Module").category("catModule").onlyOnQualifiers(Qualifiers.MODULE).build(),
+        PropertyDefinition.builder("view").name("View").category("catView").onlyOnQualifiers(Qualifiers.VIEW).build()
         );
 
     assertThat(def.getPropertiesByCategory(null).keySet()).containsOnly("catGlobal1", "catGlobal2");
@@ -121,19 +131,30 @@ public class PropertyDefinitionsTest {
     assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule");
     assertThat(def.getPropertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly("catView");
     assertThat(def.getPropertiesByCategory("Unkown").keySet()).isEmpty();
+
+    assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses"), new Category("catGlobal1"),
+        new Category("catGlobal2"));
+    assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catProject"));
+    assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catModule"));
+    assertThat(def.propertiesByCategory(Qualifiers.VIEW).keySet()).containsOnly(new Category("catView"));
+    assertThat(def.propertiesByCategory("Unkown").keySet()).isEmpty();
   }
 
   @Test
   public void should_group_by_subcategory() {
     PropertyDefinitions def = new PropertyDefinitions(
-      PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subCategory("sub1").build(),
-      PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subCategory("sub2").build(),
-      PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(),
-      PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build()
+        PropertyDefinition.builder("global1").name("Global1").category("catGlobal1").subCategory("sub1").build(),
+        PropertyDefinition.builder("global2").name("Global2").category("catGlobal1").subCategory("sub2").build(),
+        PropertyDefinition.builder("global3").name("Global3").category("catGlobal1").build(),
+        PropertyDefinition.builder("global4").name("Global4").category("catGlobal2").build()
         );
 
     assertThat(def.getPropertiesByCategory(null).get("catGlobal1").keySet()).containsOnly("catGlobal1", "sub1", "sub2");
     assertThat(def.getPropertiesByCategory(null).get("catGlobal2").keySet()).containsOnly("catGlobal2");
+
+    assertThat(def.propertiesByCategory(null).get(new Category("catGlobal1")).keySet()).containsOnly(new SubCategory("catGlobal1"), new SubCategory("sub1"),
+        new SubCategory("sub2"));
+    assertThat(def.propertiesByCategory(null).get(new Category("catGlobal2")).keySet()).containsOnly(new SubCategory("catGlobal2"));
   }
 
   @Test
@@ -143,6 +164,11 @@ public class PropertyDefinitionsTest {
     assertThat(def.getPropertiesByCategory().keySet()).containsOnly("catGlobal1", "catGlobal2");
     assertThat(def.getPropertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly("catProject");
     assertThat(def.getPropertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly("catModule");
+
+    assertThat(def.propertiesByCategory(null).keySet()).containsOnly(new Category("encryption"), new Category("email"), new Category("licenses"), new Category("catglobal1"),
+        new Category("catglobal2"));
+    assertThat(def.propertiesByCategory(Qualifiers.PROJECT).keySet()).containsOnly(new Category("catproject"));
+    assertThat(def.propertiesByCategory(Qualifiers.MODULE).keySet()).containsOnly(new Category("catmodule"));
   }
 
   private void assertProperties(PropertyDefinitions definitions) {
index cc099e2d303fcb6665943df54e96a5fec3892594..13032ed779ad1c76dbd6bc8db84ebf6b34fb7cab 100644 (file)
@@ -258,11 +258,51 @@ class ApplicationController < ActionController::Base
   end
 
   def category_name(category)
-    message("property.category.#{category}", :default => category)
+    # Try with lowercase key then with original key for backward compatibility
+    message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey))
   end
 
   def subcategory_name(category, subcategory)
-    message("property.category.#{category}.#{subcategory}", :default => subcategory)
+    if (category.key == subcategory.key)
+      # If subcategory == category then it is the default one
+      category_name(category)
+    else
+      # Try with lowercase key then with original key for backward compatibility
+      message("property.category.#{category.key}.#{subcategory.key}",
+        :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey))
+    end
+  end
+
+  def processProperties(definitions_per_category)
+    @categories = by_category_name(definitions_per_category.keys)
+
+    default_category = @categories.empty? ? nil : @categories[0]
+
+    if params[:category].nil?
+      default_category = @categories.empty? ? nil : @categories[0]
+      @category = default_category
+    else
+      @category = @categories.select {|c| c == Java::OrgSonarApiConfig::Category.new(params[:category])}.first
+      not_found('category') if @category.nil?
+    end
+
+    unless @category.isSpecial then
+      @subcategories_per_categories = {}
+      definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) }
+
+      if params[:subcategory].nil?
+        default_subcategory =
+                @subcategories_per_categories[@category].nil? ? nil :
+                  ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0])
+        @subcategory = default_subcategory
+      else
+        @subcategory = @subcategories_per_categories[@category].select {|s| s == Java::OrgSonarApiConfig::SubCategory.new(params[:subcategory])}.first
+        not_found('subcategory') if @subcategory.nil?
+      end
+
+      @definitions = definitions_per_category[@category] || {}
+      @definitions = @definitions[@subcategory] || []
+    end
   end
 
 end
index e7fef2f9573bbb0c92b6e20ef72f3f871153e287..ed99ec19552ea5a9bc7eda143f8fdb3ef606ae51 100644 (file)
@@ -239,30 +239,12 @@ class ProjectController < ApplicationController
     @resource = get_current_project(params[:id])
 
     @snapshot = @resource.last_snapshot
-    if @resource && !java_facade.getResourceTypeBooleanProperty(@resource.qualifier, 'configurable')
+    if !java_facade.getResourceTypeBooleanProperty(@resource.qualifier, 'configurable')
       redirect_to :action => 'index', :id => params[:id]
     end
 
-    definitions_per_category = java_facade.propertyDefinitions.getPropertiesByCategory(@resource ? @resource.qualifier : nil)
-    @categories = definitions_per_category.keys || []
-    @categories = by_category_name(@categories)
-
-    default_category = nil
-    default_category = @categories[0] if !@categories.empty?
-    @category = params[:category] || default_category
-
-    not_found('category') unless @categories.include? @category
-
-    @subcategories_per_categories = {}
-    definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) }
-
-    default_subcategory =
-      @subcategories_per_categories[@category].nil? ? nil :
-        ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0])
-    @subcategory = params[:subcategory] || default_subcategory
-
-    @definitions = definitions_per_category[@category] || {}
-    @definitions = @definitions[@subcategory] || []
+    definitions_per_category = java_facade.propertyDefinitions.propertiesByCategory(@resource.qualifier)
+    processProperties(definitions_per_category)
   end
 
   def update_version
index ed05613c90db3dd9b4227e5ea9947be2a4ff8cfc..a1c8b353fabfde8215d435f4056b3da2e67e3ef1 100644 (file)
@@ -21,11 +21,6 @@ class SettingsController < ApplicationController
 
   SECTION=Navigation::SECTION_CONFIGURATION
 
-  LICENSES_CATEGORY='Licenses'
-  SERVER_ID_SUBCATEGORY='server_id'
-  SPECIAL_CATEGORIES=%w(email encryption) + [LICENSES_CATEGORY]
-
-
   verify :method => :post, :only => %w(update), :redirect_to => {:action => :index}
   before_filter :admin_required, :only => %w(index)
 
@@ -103,30 +98,8 @@ class SettingsController < ApplicationController
   end
 
   def load_properties
-    definitions_per_category = java_facade.propertyDefinitions.getPropertiesByCategory(@resource ? @resource.qualifier : nil)
-    @categories = definitions_per_category.keys + SPECIAL_CATEGORIES
-    @categories = by_category_name(@categories.uniq)
-
-    default_category = @categories.empty? ? nil : @categories[0]
-    @category = params[:category] || default_category
-
-    not_found('category') unless @categories.include? @category
-
-    @subcategories_per_categories = {}
-    definitions_per_category.each {|category, definitions_per_subcategories| @subcategories_per_categories.store(category, by_subcategory_name(category, definitions_per_subcategories.keys)) }
-
-    if (@subcategories_per_categories[LICENSES_CATEGORY].nil?)
-      @subcategories_per_categories.store(LICENSES_CATEGORY, [SERVER_ID_SUBCATEGORY])
-    else
-      @subcategories_per_categories[LICENSES_CATEGORY].push(SERVER_ID_SUBCATEGORY)
-    end
-
-    default_subcategory =
-      @subcategories_per_categories[@category].nil? ? nil :
-        ((@subcategories_per_categories[@category].include? @category) ? @category : @subcategories_per_categories[@category][0])
-    @subcategory = params[:subcategory] || default_subcategory
-
-    @definitions = definitions_per_category[@category] || {}
-    @definitions = @definitions[@subcategory] || []
+    definitions_per_category = java_facade.propertyDefinitions.propertiesByCategory(nil)
+    processProperties(definitions_per_category)
   end
+
 end
index 5361d4b3f9a7389255f69c95185d99ee94c2245b..ced1751e0a1bc34d44bfda2dd569e0b186792798 100644 (file)
@@ -21,15 +21,18 @@ module SettingsHelper
   include PropertiesHelper
 
   def category_name(category)
-    message("property.category.#{category}", :default => category)
+    # Try with lowercase key then with original key for backward compatibility
+    message("property.category.#{category.key}", :default => message("property.category.#{category.originalKey}", :default => category.originalKey))
   end
 
   def subcategory_name(category, subcategory)
-    if (category == subcategory)
+    if (category.key == subcategory.key)
       # If subcategory == category then it is the default one
       category_name(category)
     else
-      message("property.category.#{category}.#{subcategory}", :default => subcategory)
+      # Try with lowercase key then with original key for backward compatibility
+      message("property.category.#{category.key}.#{subcategory.key}",
+        :default => message("property.category.#{category.originalKey}.#{subcategory.originalKey}", :default => subcategory.originalKey))
     end
   end
 
@@ -62,11 +65,11 @@ module SettingsHelper
   end
 
   def category_desc(category)
-    message("property.category.#{category}.description", :default => '')
+    message("property.category.#{category.key}.description", :default => '')
   end
 
   def subcategory_desc(category, subcategory)
-    message("property.category.#{category}.#{subcategory}.description", :default => '')
+    message("property.category.#{category.key}.#{subcategory.key}.description", :default => '')
   end
 
   def property_value(property)
index 6687598bd4f65a2a71db872af8ed60b33f2472da..ce676b40dd5f2709a778feb3bd9cbdbd7e9289d9 100644 (file)
@@ -1,7 +1,7 @@
-<% if SettingsController::SPECIAL_CATEGORIES.include?(@category) && @category != SettingsController::LICENSES_CATEGORY -%>
-  <%= render 'special', :url => url_for(:controller => "#{@category}_configuration") -%>
+<% if @category.isSpecial -%>
+  <%= render 'special', :url => url_for(:controller => "#{@category.key}_configuration") -%>
 <% else -%>
-  <% form_remote_tag :url => {:controller => 'settings', :action => 'update', :category => @category, :subcategory => @subcategory, :resource_id => @resource ? @resource.id : nil},
+  <% form_remote_tag :url => {:controller => 'settings', :action => 'update', :category => @category.key, :subcategory => @subcategory.key, :resource_id => @resource ? @resource.id : nil},
                      :method => :post,
                      :before => "$('submit_settings').hide();$('loading_settings').show();",
                      :update => 'properties',
     <ul class="tabs2">
       <% subcategories.each do |subcategory| -%>
         <li>
-          <%= link_to subcategory_name(@category, subcategory), {:controller => @resource ? 'project' : 'settings', :action => @resource ? 'settings' : 'index', :category => @category, :subcategory => subcategory, :id => @resource ? @resource.id : nil}, :class => @subcategory==subcategory ? 'selected' : nil -%>
+          <%= link_to subcategory_name(@category, subcategory), {:controller => @resource ? 'project' : 'settings', :action => @resource ? 'settings' : 'index', :category => @category.key, :subcategory => subcategory.key, :id => @resource ? @resource.id : nil}, :class => @subcategory==subcategory ? 'selected' : nil -%>
         </li>
       <% end -%>
     </ul>
-    <% if @category == SettingsController::LICENSES_CATEGORY && @subcategory == SettingsController::SERVER_ID_SUBCATEGORY %>
-      <%= render 'special', :url => url_for(:controller => "#{SettingsController::SERVER_ID_SUBCATEGORY}_configuration") -%>
+    <% if @subcategory.isSpecial %>
+      <%= render 'special', :url => url_for(:controller => "#{@subcategory.key}_configuration") -%>
     <% else %>
       <table class="data marginbottom10">
         <thead>
-        <% if @subcategory == @category && !category_desc(@category).blank? -%>
+        <% if @subcategory.key == @category.key && !category_desc(@category).blank? -%>
           <tr>
             <td class="categoryDescription"><%= category_desc(@category) -%> </td>
           </tr>
         <% end -%>
-        <% if @subcategory != @category && !subcategory_desc(@category, @subcategory).blank? -%>
+        <% if @subcategory.key != @category.key && !subcategory_desc(@category, @subcategory).blank? -%>
           <tr>
             <td><%= subcategory_desc(@category, @subcategory) -%> </td>
           </tr>
index 99e1dc041a5906391339f95db20b0be703c7d861..323ea8e0e05ee96712aafeb4134b11ecb87a30c0 100644 (file)
@@ -12,8 +12,8 @@
           </thead>
           <tbody>
           <% @categories.each do |category| -%>
-            <tr id="select_<%= category -%>" class="select <%= cycle('even', 'odd', :name => 'category') -%> <%= 'selected' if @category==category -%>">
-              <td class="category"><%= link_to category_name(category), :category => category -%></td>
+            <tr id="select_<%= category.key -%>" class="select <%= cycle('even', 'odd', :name => 'category') -%> <%= 'selected' if @category.key==category.key -%>">
+              <td class="category"><%= link_to category_name(category), :category => category.key -%></td>
             </tr>
           <% end -%>
           </tbody>