]> source.dussan.org Git - gitblit.git/commitdiff
Documentation. Refactoring class names. Re-encapsulate settings.
authorJames Moger <james.moger@gitblit.com>
Sat, 22 Oct 2011 13:01:20 +0000 (09:01 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 22 Oct 2011 13:01:20 +0000 (09:01 -0400)
22 files changed:
docs/01_setup.mkd
docs/02_rpc.mkd
src/com/gitblit/Constants.java
src/com/gitblit/GitBlit.java
src/com/gitblit/RpcServlet.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/client/GitblitClient.java [new file with mode: 0644]
src/com/gitblit/client/GitblitModel.java [deleted file]
src/com/gitblit/client/GitblitPanel.java
src/com/gitblit/client/RegistrationsDialog.java
src/com/gitblit/client/RegistrationsModel.java [deleted file]
src/com/gitblit/client/RegistrationsTableModel.java [new file with mode: 0644]
src/com/gitblit/client/RepositoriesModel.java [deleted file]
src/com/gitblit/client/RepositoriesTableModel.java [new file with mode: 0644]
src/com/gitblit/client/SettingsModel.java [deleted file]
src/com/gitblit/client/SettingsTableModel.java [new file with mode: 0644]
src/com/gitblit/client/UsersModel.java [deleted file]
src/com/gitblit/client/UsersTableModel.java [new file with mode: 0644]
src/com/gitblit/models/ServerSettings.java [new file with mode: 0644]
src/com/gitblit/models/ServerStatus.java
src/com/gitblit/utils/RpcUtils.java
tests/com/gitblit/tests/RpcTests.java

index c7a8ff61901da709dc880bbe85b1ee5e077bca3b..b2c5b2f86a8adce6d8fc229e47e131c8370e3d9a 100644 (file)
@@ -134,6 +134,7 @@ All repository settings are stored within the repository `.git/config` file unde
            showReadme = false\r
            federationStrategy = FEDERATE_THIS\r
            isFederated = false\r
+           skipSizeCalculation = false\r
            federationSets = \r
 \r
 #### Repository Names\r
index b01eb6798d0fdebc8ba37f78c6a2f0ec2e196583..94739ca36356a3089b6a3a525cf42147e0715a3d 100644 (file)
@@ -30,7 +30,8 @@ The Gitblit RPC mechanism, like the Gitblit JGit servlet, syndication/feed servl
 <tr><td>LIST_FEDERATION_RESULTS</td><td>-</td><td><em>admin</em></td><td>-</td><td>List&lt;FederationModel&gt;</td></tr>\r
 <tr><td>LIST_FEDERATION_PROPOSALS</td><td>-</td><td><em>admin</em></td><td>-</td><td>List&lt;FederationProposal&gt;</td></tr>\r
 <tr><td>LIST_FEDERATION_SETS</td><td>-</td><td><em>admin</em></td><td>-</td><td>List&lt;FederationSet&gt;</td></tr>\r
-<tr><td>LIST_SETTINGS</td><td>-</td><td><em>admin</em></td><td>-</td><td>Map&lt;String, SettingModel&gt;</td></tr>\r
+<tr><td>LIST_SETTINGS</td><td>-</td><td><em>admin</em></td><td>-</td><td>ServerSettings (see example below)</td></tr>\r
+<tr><td>LIST_STATUS</td><td>-</td><td><em>admin</em></td><td>-</td><td>ServerStatus (see example below)</td></tr>\r
 </table>\r
 \r
 ### RPC/HTTP Response Codes\r
@@ -55,6 +56,8 @@ One obvious goal of a Gitblit RPC mechanism would be to have an EGit Feature tha
 \r
 This particular project should not be difficult as the only external dependency for `com.gitblit.utils.RpcUtils` is [google-gson](http://google-gson.googlecode.com) which is already a dependency of the EGit/GitHub Mylyn feature.\r
 \r
+One proposal from the EGit team is to define a common JSON RPC method for enumeration of repositories which can be implemented by Git hosts.  The EGit team would then implement the UI and the client-side enumeration code.  This idea was raised as part of this [feature request for EGit](https://bugs.eclipse.org/bugs/show_bug.cgi?id=361251).\r
+\r
 Currently this project is in the planning stage.\r
 \r
 ### Example: LIST_REPOSITORIES\r
@@ -80,6 +83,7 @@ Currently this project is in the planning stage.
       "libraries"\r
     ],\r
     "isFederated": false,\r
+    "skipSizeCalculation": false,\r
     "size": "102 KB"\r
   },\r
   "https://localhost/git/libraries/smack.git": {\r
@@ -97,6 +101,7 @@ Currently this project is in the planning stage.
     "federationStrategy": "FEDERATE_THIS",\r
     "federationSets": [],\r
     "isFederated": false,\r
+    "skipSizeCalculation": false,\r
     "size": "4.8 MB"\r
   }\r
 }\r
@@ -157,28 +162,58 @@ The original repository name is specified in the *name* url parameter.  The new
 \r
 ### Example: LIST_SETTINGS\r
 **url**: https://localhost/rpc?req=LIST_SETTINGS  \r
-**response body**: Map&lt;String, SettingModel&gt;\r
+**response body**: ServerSettings\r
 <pre>\r
 {\r
-  "web.siteName": {\r
-    "name": "web.siteName",\r
-    "currentValue": "",\r
-    "defaultValue": "",\r
-    "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",\r
-    "since": "0.5.0",\r
-    "caseSensitive": false,\r
-    "restartRequired": false,\r
-    "spaceDelimited": false\r
-  },\r
-  "web.summaryCommitCount": {\r
-    "name": "web.summaryCommitCount",\r
-    "currentValue": "16",\r
-    "defaultValue": "16",\r
-    "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",\r
-    "since": "0.5.0",\r
-    "caseSensitive": false,\r
-    "restartRequired": false,\r
-    "spaceDelimited": false\r
+  "settings": {\r
+      "web.siteName": {\r
+        "name": "web.siteName",\r
+        "currentValue": "",\r
+        "defaultValue": "",\r
+        "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",\r
+        "since": "0.5.0",\r
+        "caseSensitive": false,\r
+        "restartRequired": false,\r
+        "spaceDelimited": false\r
+      },\r
+      "web.summaryCommitCount": {\r
+        "name": "web.summaryCommitCount",\r
+        "currentValue": "16",\r
+        "defaultValue": "16",\r
+        "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",\r
+        "since": "0.5.0",\r
+        "caseSensitive": false,\r
+        "restartRequired": false,\r
+        "spaceDelimited": false\r
+      }\r
   }\r
 }\r
+</pre>\r
+\r
+### Example: LIST_STATUS\r
+**url**: https://localhost/rpc?req=LIST_STATUS  \r
+**response body**: ServerStatus\r
+<pre>\r
+{\r
+  "bootDate": "2011-10-22T12:13:00Z",\r
+  "systemProperties": {\r
+    "file.encoding": "Cp1252",\r
+    "java.home": "C:\\Program Files\\Java\\jdk1.6.0_26\\jre",\r
+    "java.io.tmpdir": "C:\\Users\\JAMESM~1\\AppData\\Local\\Temp\\",\r
+    "java.runtime.name": "Java(TM) SE Runtime Environment",\r
+    "java.runtime.version": "1.6.0_26-b03",\r
+    "java.vendor": "Sun Microsystems Inc.",\r
+    "java.version": "1.6.0_26",\r
+    "java.vm.info": "mixed mode",\r
+    "java.vm.name": "Java HotSpot(TM) 64-Bit Server VM",\r
+    "java.vm.vendor": "Sun Microsystems Inc.",\r
+    "java.vm.version": "20.1-b02",\r
+    "os.arch": "amd64",\r
+    "os.name": "Windows 7",\r
+    "os.version": "6.1"\r
+  },\r
+  "heapAllocated": 128057344,\r
+  "heapFree": 120399168,\r
+  "heapSize": 1899560960\r
+}\r
 </pre>
\ No newline at end of file
index f3ff6c446a10999f19bfab25b43978f4c225f3cc..79dfaf6a9fa791b09e8fe233b1ec7ad6ad4cddc8 100644 (file)
@@ -205,7 +205,7 @@ public class Constants {
                LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,\r
                SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,\r
                LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS,\r
-               LIST_SERVER_STATUS;\r
+               LIST_STATUS;\r
 \r
                public static RpcRequest fromName(String name) {\r
                        for (RpcRequest type : values()) {\r
index 238c01f7faefc9f2a26b84ebb5e82ea94176b5d4..eaf6a9576ae5c5733c5a91f77e98dc6d692b209d 100644 (file)
@@ -30,7 +30,6 @@ import java.util.HashMap;
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Map.Entry;\r
-import java.util.TreeMap;\r
 import java.util.concurrent.ConcurrentHashMap;\r
 import java.util.concurrent.Executors;\r
 import java.util.concurrent.ScheduledExecutorService;\r
@@ -70,6 +69,7 @@ import com.gitblit.models.ObjectCache;
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.ServerStatus;\r
 import com.gitblit.models.SettingModel;\r
+import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ByteFormat;\r
 import com.gitblit.utils.FederationUtils;\r
@@ -123,7 +123,7 @@ public class GitBlit implements ServletContextListener {
 \r
        private IStoredSettings settings;\r
 \r
-       private Map<String, SettingModel> settingModels;\r
+       private ServerSettings settingsModel;\r
 \r
        private ServerStatus serverStatus;\r
 \r
@@ -1275,16 +1275,12 @@ public class GitBlit implements ServletContextListener {
        /**\r
         * Returns the descriptions/comments of the Gitblit config settings.\r
         * \r
-        * @return Map<String, SettingModel>\r
+        * @return SettingsModel\r
         */\r
-       public Map<String, SettingModel> getSettingModels() {\r
+       public ServerSettings getSettingsModel() {\r
                // ensure that the current values are updated in the setting models\r
-               for (String key : settings.getAllKeys(null)) {\r
-                       if (settingModels.containsKey(key)) {\r
-                               settingModels.get(key).currentValue = settings.getString(key, "");\r
-                       }\r
-               }\r
-               return settingModels;\r
+               settingsModel.updateCurrentValues(settings);\r
+               return settingsModel;\r
        }\r
 \r
        /**\r
@@ -1294,8 +1290,8 @@ public class GitBlit implements ServletContextListener {
         * \r
         * @return Map<String, SettingModel>\r
         */\r
-       private Map<String, SettingModel> loadSettingModels() {\r
-               Map<String, SettingModel> map = new TreeMap<String, SettingModel>();\r
+       private ServerSettings loadSettingModels() {\r
+               ServerSettings settingsModel = new ServerSettings();\r
                try {\r
                        // Read bundled Gitblit properties to extract setting descriptions.\r
                        // This copy is pristine and only used for populating the setting\r
@@ -1337,7 +1333,7 @@ public class GitBlit implements ServletContextListener {
                                                setting.defaultValue = kvp[1].trim();\r
                                                setting.currentValue = setting.defaultValue;\r
                                                setting.description = description.toString().trim();\r
-                                               map.put(key, setting);\r
+                                               settingsModel.add(setting);\r
                                                description.setLength(0);\r
                                                setting = new SettingModel();\r
                                        }\r
@@ -1349,7 +1345,7 @@ public class GitBlit implements ServletContextListener {
                } catch (IOException e) {\r
                        logger.error("Failed to load resource copy of gitblit.properties");\r
                }\r
-               return map;\r
+               return settingsModel;\r
        }\r
 \r
        /**\r
@@ -1409,7 +1405,7 @@ public class GitBlit implements ServletContextListener {
        @Override\r
        public void contextInitialized(ServletContextEvent contextEvent) {\r
                servletContext = contextEvent.getServletContext();\r
-               settingModels = loadSettingModels();\r
+               settingsModel = loadSettingModels();\r
                if (settings == null) {\r
                        // Gitblit WAR is running in a servlet container\r
                        WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());\r
index 6a8c2c5977c22b1f098bd3d3f4bb326fc6be5ae7..ceed35e193cc2f5a2a337d0168b360e411d64bcc 100644 (file)
@@ -182,8 +182,8 @@ public class RpcServlet extends JsonServlet {
                        }\r
                } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
                        // return the server's settings\r
-                       result = GitBlit.self().getSettingModels();\r
-               } else if (RpcRequest.LIST_SERVER_STATUS.equals(reqType)) {\r
+                       result = GitBlit.self().getSettingsModel();\r
+               } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
                        // return the server's status information\r
                        result = GitBlit.self().getStatus();\r
                }\r
index 0a1ddd93f22a071dadf580276c8ff09f78e84ebd..988f8fb0c46bd74cd5a375b817d7514654a272d2 100644 (file)
@@ -29,7 +29,6 @@ import java.util.ArrayList;
 import java.util.Arrays;\r
 import java.util.HashSet;\r
 import java.util.List;\r
-import java.util.Map;\r
 import java.util.Set;\r
 \r
 import javax.swing.ImageIcon;\r
@@ -48,7 +47,7 @@ import javax.swing.KeyStroke;
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.SettingModel;\r
+import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -58,10 +57,10 @@ public class EditUserDialog extends JDialog {
 \r
        private final UserModel user;\r
 \r
-       private final Map<String, SettingModel> settings;\r
+       private final ServerSettings settings;\r
 \r
        private boolean isCreate;\r
-       \r
+\r
        private boolean canceled = true;\r
 \r
        private JTextField usernameField;\r
@@ -78,13 +77,13 @@ public class EditUserDialog extends JDialog {
 \r
        private Set<String> usernames;\r
 \r
-       public EditUserDialog(Map<String, SettingModel> settings) {\r
+       public EditUserDialog(ServerSettings settings) {\r
                this(new UserModel(""), settings);\r
                this.isCreate = true;\r
-               setTitle(Translation.get("gb.newUser"));                \r
+               setTitle(Translation.get("gb.newUser"));\r
        }\r
 \r
-       public EditUserDialog(UserModel anUser, Map<String, SettingModel> settings) {\r
+       public EditUserDialog(UserModel anUser, ServerSettings settings) {\r
                super();\r
                this.user = new UserModel("");\r
                this.settings = settings;\r
@@ -95,7 +94,7 @@ public class EditUserDialog extends JDialog {
                setTitle(Translation.get("gb.edit") + ": " + anUser.username);\r
                setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage());\r
        }\r
-       \r
+\r
        @Override\r
        protected JRootPane createRootPane() {\r
                KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);\r
@@ -203,8 +202,8 @@ public class EditUserDialog extends JDialog {
                }\r
                char[] pw = passwordField.getPassword();\r
                if (pw == null || pw.length < minLength) {\r
-                       error(MessageFormat.format(\r
-                                       "Password is too short. Minimum length is {0} characters.", minLength));\r
+                       error(MessageFormat.format("Password is too short. Minimum length is {0} characters.",\r
+                                       minLength));\r
                        return false;\r
                }\r
                char[] cpw = confirmPasswordField.getPassword();\r
diff --git a/src/com/gitblit/client/GitblitClient.java b/src/com/gitblit/client/GitblitClient.java
new file mode 100644 (file)
index 0000000..76a6731
--- /dev/null
@@ -0,0 +1,200 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.io.IOException;\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import com.gitblit.GitBlitException.ForbiddenException;\r
+import com.gitblit.GitBlitException.UnauthorizedException;\r
+import com.gitblit.Keys;\r
+import com.gitblit.models.FederationModel;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.ServerSettings;\r
+import com.gitblit.models.ServerStatus;\r
+import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.RpcUtils;\r
+\r
+/**\r
+ * GitblitClient is a object that retrieves data from a Gitblit server, caches\r
+ * it for local operations, and allows updating or creating Gitblit objects.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class GitblitClient implements Serializable {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public final String url;\r
+\r
+       public final String account;\r
+\r
+       private final char[] password;\r
+\r
+       private volatile boolean isAdmin;\r
+\r
+       private volatile ServerSettings settings;\r
+\r
+       private final List<RepositoryModel> allRepositories;\r
+\r
+       private final List<UserModel> allUsers;\r
+\r
+       private final List<FederationModel> federationRegistrations;\r
+\r
+       private ServerStatus status;\r
+\r
+       public GitblitClient(String url, String account, char[] password) {\r
+               this.url = url;\r
+               this.account = account;\r
+               this.password = password;\r
+\r
+               this.allUsers = new ArrayList<UserModel>();\r
+               this.allRepositories = new ArrayList<RepositoryModel>();\r
+               this.federationRegistrations = new ArrayList<FederationModel>();\r
+       }\r
+\r
+       public void login() throws IOException {\r
+               refreshRepositories();\r
+\r
+               try {\r
+                       settings = RpcUtils.getSettings(url, account, password);\r
+                       status = RpcUtils.getStatus(url, account, password);\r
+                       refreshUsers();\r
+                       isAdmin = true;\r
+               } catch (UnauthorizedException e) {\r
+               } catch (ForbiddenException e) {\r
+               } catch (IOException e) {\r
+                       System.err.println(e.getMessage());\r
+               }\r
+       }\r
+\r
+       public boolean allowAdmin() {\r
+               return isAdmin;\r
+       }\r
+\r
+       public boolean isOwner(RepositoryModel model) {\r
+               return account != null && account.equalsIgnoreCase(model.owner);\r
+       }\r
+\r
+       public ServerSettings getSettings() {\r
+               return settings;\r
+       }\r
+\r
+       public ServerStatus getStatus() {\r
+               return status;\r
+       }\r
+\r
+       public String getSettingDescription(String key) {\r
+               return settings.get(key).description;\r
+       }\r
+\r
+       public List<RepositoryModel> refreshRepositories() throws IOException {\r
+               Map<String, RepositoryModel> repositories = RpcUtils\r
+                               .getRepositories(url, account, password);\r
+               allRepositories.clear();\r
+               allRepositories.addAll(repositories.values());\r
+               Collections.sort(allRepositories);\r
+               return allRepositories;\r
+       }\r
+\r
+       public List<UserModel> refreshUsers() throws IOException {\r
+               List<UserModel> users = RpcUtils.getUsers(url, account, password);\r
+               allUsers.clear();\r
+               allUsers.addAll(users);\r
+               return allUsers;\r
+       }\r
+\r
+       public List<FederationModel> refreshFederationRegistrations() throws IOException {\r
+               List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);\r
+               federationRegistrations.clear();\r
+               federationRegistrations.addAll(list);\r
+               return federationRegistrations;\r
+       }\r
+\r
+       public List<UserModel> getUsers() {\r
+               return allUsers;\r
+       }\r
+\r
+       public List<String> getUsernames() {\r
+               List<String> usernames = new ArrayList<String>();\r
+               for (UserModel user : this.allUsers) {\r
+                       usernames.add(user.username);\r
+               }\r
+               Collections.sort(usernames);\r
+               return usernames;\r
+       }\r
+\r
+       public List<String> getPermittedUsernames(RepositoryModel repository) {\r
+               List<String> usernames = new ArrayList<String>();\r
+               for (UserModel user : this.allUsers) {\r
+                       if (user.repositories.contains(repository.name)) {\r
+                               usernames.add(user.username);\r
+                       }\r
+               }\r
+               return usernames;\r
+       }\r
+\r
+       public List<String> getFederationSets() {\r
+               return settings.get(Keys.federation.sets).getStrings();\r
+       }\r
+\r
+       public List<RepositoryModel> getRepositories() {\r
+               return allRepositories;\r
+       }\r
+\r
+       public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)\r
+                       throws IOException {\r
+               boolean success = true;\r
+               success &= RpcUtils.createRepository(repository, url, account, password);\r
+               if (permittedUsers.size() > 0) {\r
+                       // if new repository has named members, set them\r
+                       success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
+                                       password);\r
+               }\r
+               return success;\r
+       }\r
+\r
+       public boolean updateRepository(String name, RepositoryModel repository,\r
+                       List<String> permittedUsers) throws IOException {\r
+               boolean success = true;\r
+               success &= RpcUtils.updateRepository(name, repository, url, account, password);\r
+               // always set the repository members\r
+               success &= RpcUtils\r
+                               .setRepositoryMembers(repository, permittedUsers, url, account, password);\r
+               return success;\r
+       }\r
+\r
+       public boolean deleteRepository(RepositoryModel repository) throws IOException {\r
+               return RpcUtils.deleteRepository(repository, url, account, password);\r
+       }\r
+\r
+       public boolean createUser(UserModel user) throws IOException {\r
+               return RpcUtils.createUser(user, url, account, password);\r
+       }\r
+\r
+       public boolean updateUser(String name, UserModel user) throws IOException {\r
+               return RpcUtils.updateUser(name, user, url, account, password);\r
+       }\r
+\r
+       public boolean deleteUser(UserModel user) throws IOException {\r
+               return RpcUtils.deleteUser(user, url, account, password);\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/GitblitModel.java b/src/com/gitblit/client/GitblitModel.java
deleted file mode 100644 (file)
index 55e74b9..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.io.IOException;\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import com.gitblit.GitBlitException.ForbiddenException;\r
-import com.gitblit.GitBlitException.UnauthorizedException;\r
-import com.gitblit.Keys;\r
-import com.gitblit.models.FederationModel;\r
-import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.ServerStatus;\r
-import com.gitblit.models.SettingModel;\r
-import com.gitblit.models.UserModel;\r
-import com.gitblit.utils.RpcUtils;\r
-\r
-public class GitblitModel implements Serializable {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       public final String url;\r
-\r
-       public final String account;\r
-\r
-       private final char[] password;\r
-\r
-       private volatile boolean isAdmin;\r
-\r
-       private volatile Map<String, SettingModel> settings;\r
-\r
-       private final List<RepositoryModel> allRepositories;\r
-\r
-       private final List<UserModel> allUsers;\r
-\r
-       private final List<FederationModel> federationRegistrations;\r
-\r
-       private ServerStatus status;\r
-\r
-       public GitblitModel(String url, String account, char[] password) {\r
-               this.url = url;\r
-               this.account = account;\r
-               this.password = password;\r
-\r
-               this.allUsers = new ArrayList<UserModel>();\r
-               this.allRepositories = new ArrayList<RepositoryModel>();\r
-               this.federationRegistrations = new ArrayList<FederationModel>();\r
-       }\r
-\r
-       public void login() throws IOException {\r
-               refreshRepositories();\r
-\r
-               try {\r
-                       settings = RpcUtils.getSettings(url, account, password);\r
-                       status = RpcUtils.getStatus(url, account, password);\r
-                       refreshUsers();\r
-                       isAdmin = true;\r
-               } catch (UnauthorizedException e) {\r
-               } catch (ForbiddenException e) {\r
-               } catch (IOException e) {\r
-                       System.err.println(e.getMessage());\r
-               }\r
-       }\r
-\r
-       public boolean allowAdmin() {\r
-               return isAdmin;\r
-       }\r
-\r
-       public boolean isOwner(RepositoryModel model) {\r
-               return account != null && account.equalsIgnoreCase(model.owner);\r
-       }\r
-\r
-       public Map<String, SettingModel> getSettings() {\r
-               return settings;\r
-       }\r
-\r
-       public String getSettingDescription(String key) {\r
-               return settings.get(key).description;\r
-       }\r
-\r
-       public List<RepositoryModel> refreshRepositories() throws IOException {\r
-               Map<String, RepositoryModel> repositories = RpcUtils\r
-                               .getRepositories(url, account, password);\r
-               allRepositories.clear();\r
-               allRepositories.addAll(repositories.values());\r
-               Collections.sort(allRepositories);\r
-               return allRepositories;\r
-       }\r
-\r
-       public List<UserModel> refreshUsers() throws IOException {\r
-               List<UserModel> users = RpcUtils.getUsers(url, account, password);\r
-               allUsers.clear();\r
-               allUsers.addAll(users);\r
-               return allUsers;\r
-       }\r
-\r
-       public List<FederationModel> refreshFederationRegistrations() throws IOException {\r
-               List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);\r
-               federationRegistrations.clear();\r
-               federationRegistrations.addAll(list);\r
-               return federationRegistrations;\r
-       }\r
-\r
-       public List<UserModel> getUsers() {\r
-               return allUsers;\r
-       }\r
-\r
-       public List<String> getUsernames() {\r
-               List<String> usernames = new ArrayList<String>();\r
-               for (UserModel user : this.allUsers) {\r
-                       usernames.add(user.username);\r
-               }\r
-               Collections.sort(usernames);\r
-               return usernames;\r
-       }\r
-\r
-       public List<String> getPermittedUsernames(RepositoryModel repository) {\r
-               List<String> usernames = new ArrayList<String>();\r
-               for (UserModel user : this.allUsers) {\r
-                       if (user.repositories.contains(repository.name)) {\r
-                               usernames.add(user.username);\r
-                       }\r
-               }\r
-               return usernames;\r
-       }\r
-\r
-       public List<String> getFederationSets() {\r
-               return settings.get(Keys.federation.sets).getStrings();\r
-       }\r
-\r
-       public List<RepositoryModel> getRepositories() {\r
-               return allRepositories;\r
-       }\r
-\r
-       public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)\r
-                       throws IOException {\r
-               boolean success = true;\r
-               success &= RpcUtils.createRepository(repository, url, account, password);\r
-               if (permittedUsers.size() > 0) {\r
-                       // if new repository has named members, set them\r
-                       success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
-                                       password);\r
-               }\r
-               return success;\r
-       }\r
-\r
-       public boolean updateRepository(String name, RepositoryModel repository,\r
-                       List<String> permittedUsers) throws IOException {\r
-               boolean success = true;\r
-               success &= RpcUtils.updateRepository(name, repository, url, account, password);\r
-               // always set the repository members\r
-               success &= RpcUtils\r
-                               .setRepositoryMembers(repository, permittedUsers, url, account, password);\r
-               return success;\r
-       }\r
-\r
-       public boolean deleteRepository(RepositoryModel repository) throws IOException {\r
-               return RpcUtils.deleteRepository(repository, url, account, password);\r
-       }\r
-\r
-       public boolean createUser(UserModel user) throws IOException {\r
-               return RpcUtils.createUser(user, url, account, password);\r
-       }\r
-\r
-       public boolean updateUser(String name, UserModel user) throws IOException {\r
-               return RpcUtils.updateUser(name, user, url, account, password);\r
-       }\r
-\r
-       public boolean deleteUser(UserModel user) throws IOException {\r
-               return RpcUtils.deleteUser(user, url, account, password);\r
-       }\r
-}\r
index 8635b0069cce1d8ced8ed1a95f3057747ad8845d..e4c6e76c8d7593296c557135a5ef2916c6d7fb88 100644 (file)
@@ -71,21 +71,21 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private final Insets insets = new Insets(margin, margin, margin, margin);\r
 \r
-       private GitblitModel gitblit;\r
+       private GitblitClient gitblit;\r
 \r
        private JTabbedPane tabs;\r
 \r
        private JTable repositoriesTable;\r
 \r
-       private RepositoriesModel repositoriesModel;\r
+       private RepositoriesTableModel repositoriesModel;\r
 \r
        private JTable usersTable;\r
 \r
-       private UsersModel usersModel;\r
+       private UsersTableModel usersModel;\r
 \r
        private JTable settingsTable;\r
 \r
-       private SettingsModel settingsModel;\r
+       private SettingsTableModel settingsModel;\r
 \r
        private JButton createRepository;\r
 \r
@@ -99,11 +99,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private DefaultTableCellRenderer sizeRenderer;\r
 \r
-       private TableRowSorter<RepositoriesModel> defaultRepositoriesSorter;\r
+       private TableRowSorter<RepositoriesTableModel> defaultRepositoriesSorter;\r
 \r
-       private TableRowSorter<UsersModel> defaultUsersSorter;\r
+       private TableRowSorter<UsersTableModel> defaultUsersSorter;\r
 \r
-       private TableRowSorter<SettingsModel> defaultSettingsSorter;\r
+       private TableRowSorter<SettingsTableModel> defaultSettingsSorter;\r
 \r
        private JButton editRepository;\r
 \r
@@ -112,7 +112,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
        }\r
 \r
        public GitblitPanel(String url, String account, char[] password) {\r
-               this.gitblit = new GitblitModel(url, account, password);\r
+               this.gitblit = new GitblitClient(url, account, password);\r
 \r
                tabs = new JTabbedPane(JTabbedPane.BOTTOM);\r
                tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel());\r
@@ -180,17 +180,17 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                ownerRenderer.setForeground(Color.gray);\r
                ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);\r
 \r
-               repositoriesModel = new RepositoriesModel();\r
-               defaultRepositoriesSorter = new TableRowSorter<RepositoriesModel>(repositoriesModel);\r
+               repositoriesModel = new RepositoriesTableModel();\r
+               defaultRepositoriesSorter = new TableRowSorter<RepositoriesTableModel>(repositoriesModel);\r
                repositoriesTable = Utils.newTable(repositoriesModel);\r
                repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
                repositoriesTable.setRowSorter(defaultRepositoriesSorter);\r
-               repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesModel.Columns.Name.ordinal());\r
+               repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());\r
 \r
-               setRepositoryRenderer(RepositoriesModel.Columns.Name, nameRenderer, -1);\r
-               setRepositoryRenderer(RepositoriesModel.Columns.Indicators, typeRenderer, 100);\r
-               setRepositoryRenderer(RepositoriesModel.Columns.Owner, ownerRenderer, -1);\r
-               setRepositoryRenderer(RepositoriesModel.Columns.Size, sizeRenderer, 60);\r
+               setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);\r
+               setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);\r
+               setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);\r
+               setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);\r
 \r
                repositoriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
                        @Override\r
@@ -205,7 +205,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                if (selected) {\r
                                        int viewRow = repositoriesTable.getSelectedRow();\r
                                        int modelRow = repositoriesTable.convertRowIndexToModel(viewRow);\r
-                                       RepositoryModel model = ((RepositoriesModel) repositoriesTable.getModel()).list\r
+                                       RepositoryModel model = ((RepositoriesTableModel) repositoriesTable.getModel()).list\r
                                                        .get(modelRow);\r
                                        editRepository.setEnabled(singleSelection\r
                                                        && (gitblit.allowAdmin() || gitblit.isOwner(model)));\r
@@ -266,7 +266,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                return repositoriesPanel;\r
        }\r
 \r
-       private void setRepositoryRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer,\r
+       private void setRepositoryRenderer(RepositoriesTableModel.Columns col, TableCellRenderer renderer,\r
                        int maxWidth) {\r
                String name = repositoriesTable.getColumnName(col.ordinal());\r
                repositoriesTable.getColumn(name).setCellRenderer(renderer);\r
@@ -307,14 +307,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        }\r
                });\r
 \r
-               usersModel = new UsersModel();\r
-               defaultUsersSorter = new TableRowSorter<UsersModel>(usersModel);\r
+               usersModel = new UsersTableModel();\r
+               defaultUsersSorter = new TableRowSorter<UsersTableModel>(usersModel);\r
                usersTable = Utils.newTable(usersModel);\r
-               String name = usersTable.getColumnName(UsersModel.Columns.Name.ordinal());\r
+               String name = usersTable.getColumnName(UsersTableModel.Columns.Name.ordinal());\r
                usersTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
                usersTable.getColumn(name).setCellRenderer(nameRenderer);\r
                usersTable.setRowSorter(defaultUsersSorter);\r
-               usersTable.getRowSorter().toggleSortOrder(UsersModel.Columns.Name.ordinal());\r
+               usersTable.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal());\r
                usersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
 \r
                        @Override\r
@@ -381,15 +381,15 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
 \r
        private JPanel createSettingsPanel() {\r
                final SettingPanel settingPanel = new SettingPanel();\r
-               settingsModel = new SettingsModel();\r
-               defaultSettingsSorter = new TableRowSorter<SettingsModel>(settingsModel);\r
+               settingsModel = new SettingsTableModel();\r
+               defaultSettingsSorter = new TableRowSorter<SettingsTableModel>(settingsModel);\r
                settingsTable = Utils.newTable(settingsModel);\r
                settingsTable.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());\r
-               String name = settingsTable.getColumnName(UsersModel.Columns.Name.ordinal());\r
+               String name = settingsTable.getColumnName(UsersTableModel.Columns.Name.ordinal());\r
                settingsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
                settingsTable.getColumn(name).setCellRenderer(nameRenderer);\r
                settingsTable.setRowSorter(defaultSettingsSorter);\r
-               settingsTable.getRowSorter().toggleSortOrder(SettingsModel.Columns.Name.ordinal());\r
+               settingsTable.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());\r
                settingsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
 \r
                        @Override\r
@@ -496,8 +496,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        repositoriesTable.setRowSorter(defaultRepositoriesSorter);\r
                        return;\r
                }\r
-               RowFilter<RepositoriesModel, Object> containsFilter = new RowFilter<RepositoriesModel, Object>() {\r
-                       public boolean include(Entry<? extends RepositoriesModel, ? extends Object> entry) {\r
+               RowFilter<RepositoriesTableModel, Object> containsFilter = new RowFilter<RepositoriesTableModel, Object>() {\r
+                       public boolean include(Entry<? extends RepositoriesTableModel, ? extends Object> entry) {\r
                                for (int i = entry.getValueCount() - 1; i >= 0; i--) {\r
                                        if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) {\r
                                                return true;\r
@@ -506,7 +506,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                return false;\r
                        }\r
                };\r
-               TableRowSorter<RepositoriesModel> sorter = new TableRowSorter<RepositoriesModel>(\r
+               TableRowSorter<RepositoriesTableModel> sorter = new TableRowSorter<RepositoriesTableModel>(\r
                                repositoriesModel);\r
                sorter.setRowFilter(containsFilter);\r
                repositoriesTable.setRowSorter(sorter);\r
@@ -517,8 +517,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        usersTable.setRowSorter(defaultUsersSorter);\r
                        return;\r
                }\r
-               RowFilter<UsersModel, Object> containsFilter = new RowFilter<UsersModel, Object>() {\r
-                       public boolean include(Entry<? extends UsersModel, ? extends Object> entry) {\r
+               RowFilter<UsersTableModel, Object> containsFilter = new RowFilter<UsersTableModel, Object>() {\r
+                       public boolean include(Entry<? extends UsersTableModel, ? extends Object> entry) {\r
                                for (int i = entry.getValueCount() - 1; i >= 0; i--) {\r
                                        if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) {\r
                                                return true;\r
@@ -527,7 +527,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                return false;\r
                        }\r
                };\r
-               TableRowSorter<UsersModel> sorter = new TableRowSorter<UsersModel>(usersModel);\r
+               TableRowSorter<UsersTableModel> sorter = new TableRowSorter<UsersTableModel>(usersModel);\r
                sorter.setRowFilter(containsFilter);\r
                usersTable.setRowSorter(sorter);\r
        }\r
@@ -537,8 +537,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                        settingsTable.setRowSorter(defaultSettingsSorter);\r
                        return;\r
                }\r
-               RowFilter<SettingsModel, Object> containsFilter = new RowFilter<SettingsModel, Object>() {\r
-                       public boolean include(Entry<? extends SettingsModel, ? extends Object> entry) {\r
+               RowFilter<SettingsTableModel, Object> containsFilter = new RowFilter<SettingsTableModel, Object>() {\r
+                       public boolean include(Entry<? extends SettingsTableModel, ? extends Object> entry) {\r
                                for (int i = entry.getValueCount() - 1; i >= 0; i--) {\r
                                        if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) {\r
                                                return true;\r
@@ -547,7 +547,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener {
                                return false;\r
                        }\r
                };\r
-               TableRowSorter<SettingsModel> sorter = new TableRowSorter<SettingsModel>(settingsModel);\r
+               TableRowSorter<SettingsTableModel> sorter = new TableRowSorter<SettingsTableModel>(settingsModel);\r
                sorter.setRowFilter(containsFilter);\r
                settingsTable.setRowSorter(sorter);\r
        }\r
index ae53d5fac5308a2699b98d485434cdcf517682b2..71178f3054235896c4d28037d28ad86b655c0977 100644 (file)
@@ -56,7 +56,7 @@ public class RegistrationsDialog extends JDialog {
 \r
        private JTable registrationsTable;\r
 \r
-       private RegistrationsModel model;\r
+       private RegistrationsTableModel model;\r
 \r
        public RegistrationsDialog(List<GitblitRegistration> registrations,\r
                        RegistrationListener listener) {\r
@@ -83,11 +83,11 @@ public class RegistrationsDialog extends JDialog {
 \r
        private void initialize() {\r
                NameRenderer nameRenderer = new NameRenderer();\r
-               model = new RegistrationsModel(registrations);\r
+               model = new RegistrationsTableModel(registrations);\r
                registrationsTable = Utils.newTable(model);\r
                registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8);\r
 \r
-               String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal());\r
+               String id = registrationsTable.getColumnName(RegistrationsTableModel.Columns.Name.ordinal());\r
                registrationsTable.getColumn(id).setCellRenderer(nameRenderer);\r
                registrationsTable.addMouseListener(new MouseAdapter() {\r
                        public void mouseClicked(MouseEvent e) {\r
diff --git a/src/com/gitblit/client/RegistrationsModel.java b/src/com/gitblit/client/RegistrationsModel.java
deleted file mode 100644 (file)
index 8b4966c..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import javax.swing.table.AbstractTableModel;\r
-\r
-/**\r
- * Table model of a list of Gitblit server registrations.\r
- * \r
- * @author James Moger\r
- * \r
- */\r
-public class RegistrationsModel extends AbstractTableModel {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       List<GitblitRegistration> list;\r
-\r
-       enum Columns {\r
-               Name, URL, Last_Login;\r
-\r
-               @Override\r
-               public String toString() {\r
-                       return name().replace('_', ' ');\r
-               }\r
-       }\r
-\r
-       public RegistrationsModel(List<GitblitRegistration> list) {\r
-               this.list = list;\r
-               Collections.sort(this.list);\r
-       }\r
-\r
-       @Override\r
-       public int getRowCount() {\r
-               return list.size();\r
-       }\r
-\r
-       @Override\r
-       public int getColumnCount() {\r
-               return Columns.values().length;\r
-       }\r
-\r
-       @Override\r
-       public String getColumnName(int column) {\r
-               Columns col = Columns.values()[column];\r
-               switch (col) {\r
-               case Name:\r
-                       return Translation.get("gb.name");\r
-               case URL:\r
-                       return Translation.get("gb.url");\r
-               case Last_Login:\r
-                       return Translation.get("gb.lastLogin");\r
-               }\r
-               return "";\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
-        * \r
-        * @param columnIndex\r
-        *            the column being queried\r
-        * @return the Object.class\r
-        */\r
-       public Class<?> getColumnClass(int columnIndex) {\r
-               if (columnIndex == Columns.Last_Login.ordinal()) {\r
-                       return Date.class;\r
-               }\r
-               return String.class;\r
-       }\r
-\r
-       @Override\r
-       public Object getValueAt(int rowIndex, int columnIndex) {\r
-               GitblitRegistration model = list.get(rowIndex);\r
-               Columns col = Columns.values()[columnIndex];\r
-               switch (col) {\r
-               case Name:\r
-                       return model.name;\r
-               case URL:\r
-                       return model.url;\r
-               case Last_Login:\r
-                       return model.lastLogin;\r
-               }\r
-               return null;\r
-       }\r
-}\r
diff --git a/src/com/gitblit/client/RegistrationsTableModel.java b/src/com/gitblit/client/RegistrationsTableModel.java
new file mode 100644 (file)
index 0000000..8c6b34f
--- /dev/null
@@ -0,0 +1,102 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.Collections;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+/**\r
+ * Table model of a list of Gitblit server registrations.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RegistrationsTableModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<GitblitRegistration> list;\r
+\r
+       enum Columns {\r
+               Name, URL, Last_Login;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public RegistrationsTableModel(List<GitblitRegistration> list) {\r
+               this.list = list;\r
+               Collections.sort(this.list);\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return list.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Name:\r
+                       return Translation.get("gb.name");\r
+               case URL:\r
+                       return Translation.get("gb.url");\r
+               case Last_Login:\r
+                       return Translation.get("gb.lastLogin");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               if (columnIndex == Columns.Last_Login.ordinal()) {\r
+                       return Date.class;\r
+               }\r
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               GitblitRegistration model = list.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return model.name;\r
+               case URL:\r
+                       return model.url;\r
+               case Last_Login:\r
+                       return model.lastLogin;\r
+               }\r
+               return null;\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/RepositoriesModel.java b/src/com/gitblit/client/RepositoriesModel.java
deleted file mode 100644 (file)
index c1fead9..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import javax.swing.table.AbstractTableModel;\r
-\r
-import com.gitblit.models.RepositoryModel;\r
-\r
-/**\r
- * Table model of a list of repositories.\r
- * \r
- * @author James Moger\r
- * \r
- */\r
-public class RepositoriesModel extends AbstractTableModel {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       List<RepositoryModel> list;\r
-\r
-       enum Columns {\r
-               Name, Description, Owner, Indicators, Last_Change, Size;\r
-\r
-               @Override\r
-               public String toString() {\r
-                       return name().replace('_', ' ');\r
-               }\r
-       }\r
-\r
-       public RepositoriesModel() {\r
-               this(new ArrayList<RepositoryModel>());\r
-       }\r
-\r
-       public RepositoriesModel(List<RepositoryModel> repositories) {\r
-               this.list = repositories;\r
-               Collections.sort(this.list);\r
-       }\r
-\r
-       @Override\r
-       public int getRowCount() {\r
-               return list.size();\r
-       }\r
-\r
-       @Override\r
-       public int getColumnCount() {\r
-               return Columns.values().length;\r
-       }\r
-\r
-       @Override\r
-       public String getColumnName(int column) {\r
-               Columns col = Columns.values()[column];\r
-               switch (col) {\r
-               case Name:\r
-                       return Translation.get("gb.name");\r
-               case Description:\r
-                       return Translation.get("gb.description");\r
-               case Owner:\r
-                       return Translation.get("gb.owner");\r
-               case Last_Change:\r
-                       return Translation.get("gb.lastChange");\r
-               case Size:\r
-                       return Translation.get("gb.size");\r
-               }\r
-               return "";\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
-        * \r
-        * @param columnIndex\r
-        *            the column being queried\r
-        * @return the Object.class\r
-        */\r
-       public Class<?> getColumnClass(int columnIndex) {\r
-               Columns col = Columns.values()[columnIndex];\r
-               switch (col) {\r
-               case Name:\r
-               case Indicators:\r
-                       return RepositoryModel.class;\r
-               case Last_Change:\r
-                       return Date.class;\r
-               }\r
-               return String.class;\r
-       }\r
-\r
-       @Override\r
-       public Object getValueAt(int rowIndex, int columnIndex) {\r
-               RepositoryModel model = list.get(rowIndex);\r
-               Columns col = Columns.values()[columnIndex];\r
-               switch (col) {\r
-               case Name:\r
-                       return model;\r
-               case Description:\r
-                       return model.description;\r
-               case Owner:\r
-                       return model.owner;\r
-               case Indicators:\r
-                       return model;\r
-               case Last_Change:\r
-                       return model.lastChange;\r
-               case Size:\r
-                       return model.size;\r
-               }\r
-               return null;\r
-       }\r
-}\r
diff --git a/src/com/gitblit/client/RepositoriesTableModel.java b/src/com/gitblit/client/RepositoriesTableModel.java
new file mode 100644 (file)
index 0000000..9dd1a99
--- /dev/null
@@ -0,0 +1,124 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.models.RepositoryModel;\r
+\r
+/**\r
+ * Table model of a list of repositories.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RepositoriesTableModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<RepositoryModel> list;\r
+\r
+       enum Columns {\r
+               Name, Description, Owner, Indicators, Last_Change, Size;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public RepositoriesTableModel() {\r
+               this(new ArrayList<RepositoryModel>());\r
+       }\r
+\r
+       public RepositoriesTableModel(List<RepositoryModel> repositories) {\r
+               this.list = repositories;\r
+               Collections.sort(this.list);\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return list.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Name:\r
+                       return Translation.get("gb.name");\r
+               case Description:\r
+                       return Translation.get("gb.description");\r
+               case Owner:\r
+                       return Translation.get("gb.owner");\r
+               case Last_Change:\r
+                       return Translation.get("gb.lastChange");\r
+               case Size:\r
+                       return Translation.get("gb.size");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+               case Indicators:\r
+                       return RepositoryModel.class;\r
+               case Last_Change:\r
+                       return Date.class;\r
+               }\r
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               RepositoryModel model = list.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return model;\r
+               case Description:\r
+                       return model.description;\r
+               case Owner:\r
+                       return model.owner;\r
+               case Indicators:\r
+                       return model;\r
+               case Last_Change:\r
+                       return model.lastChange;\r
+               case Size:\r
+                       return model.size;\r
+               }\r
+               return null;\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/SettingsModel.java b/src/com/gitblit/client/SettingsModel.java
deleted file mode 100644 (file)
index af3c1b6..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.swing.table.AbstractTableModel;\r
-\r
-import com.gitblit.models.SettingModel;\r
-\r
-/**\r
- * Table model of Map<String, SettingModel>.\r
- * \r
- * @author James Moger\r
- * \r
- */\r
-public class SettingsModel extends AbstractTableModel {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       Map<String, SettingModel> settings;\r
-\r
-       List<String> keys;\r
-\r
-       enum Columns {\r
-               Name, Value;\r
-\r
-               @Override\r
-               public String toString() {\r
-                       return name().replace('_', ' ');\r
-               }\r
-       }\r
-\r
-       public SettingsModel() {\r
-               this(null);\r
-       }\r
-\r
-       public SettingsModel(Map<String, SettingModel> settings) {\r
-               setSettings(settings);\r
-       }\r
-\r
-       public void setSettings(Map<String, SettingModel> settings) {\r
-               this.settings = settings;\r
-               if (settings == null) {\r
-                       keys = new ArrayList<String>();\r
-               } else {\r
-                       keys = new ArrayList<String>(settings.keySet());\r
-                       Collections.sort(keys);\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public int getRowCount() {\r
-               return keys.size();\r
-       }\r
-\r
-       @Override\r
-       public int getColumnCount() {\r
-               return Columns.values().length;\r
-       }\r
-\r
-       @Override\r
-       public String getColumnName(int column) {\r
-               Columns col = Columns.values()[column];\r
-               switch (col) {\r
-               case Name:\r
-                       return Translation.get("gb.name");\r
-               }\r
-               return "";\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
-        * \r
-        * @param columnIndex\r
-        *            the column being queried\r
-        * @return the Object.class\r
-        */\r
-       public Class<?> getColumnClass(int columnIndex) {\r
-               if (Columns.Value.ordinal() == columnIndex) {\r
-                       return SettingModel.class;\r
-               }\r
-               return String.class;\r
-       }\r
-\r
-       @Override\r
-       public Object getValueAt(int rowIndex, int columnIndex) {\r
-               String key = keys.get(rowIndex);\r
-               SettingModel setting = settings.get(key);\r
-               Columns col = Columns.values()[columnIndex];\r
-               switch (col) {\r
-               case Name:\r
-                       return key;\r
-               case Value:\r
-                       return setting;\r
-               }\r
-               return null;\r
-       }\r
-\r
-       public SettingModel get(int modelRow) {\r
-               String key = keys.get(modelRow);\r
-               return settings.get(key);\r
-       }\r
-}\r
diff --git a/src/com/gitblit/client/SettingsTableModel.java b/src/com/gitblit/client/SettingsTableModel.java
new file mode 100644 (file)
index 0000000..e6d2313
--- /dev/null
@@ -0,0 +1,120 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.models.ServerSettings;\r
+import com.gitblit.models.SettingModel;\r
+\r
+/**\r
+ * Table model of Map<String, SettingModel>.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class SettingsTableModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       ServerSettings settings;\r
+\r
+       List<String> keys;\r
+\r
+       enum Columns {\r
+               Name, Value;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public SettingsTableModel() {\r
+               this(null);\r
+       }\r
+\r
+       public SettingsTableModel(ServerSettings settings) {\r
+               setSettings(settings);\r
+       }\r
+\r
+       public void setSettings(ServerSettings settings) {\r
+               this.settings = settings;\r
+               if (settings == null) {\r
+                       keys = new ArrayList<String>();\r
+               } else {\r
+                       keys = new ArrayList<String>(settings.getKeys());\r
+                       Collections.sort(keys);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return keys.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Name:\r
+                       return Translation.get("gb.name");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               if (Columns.Value.ordinal() == columnIndex) {\r
+                       return SettingModel.class;\r
+               }\r
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               String key = keys.get(rowIndex);\r
+               SettingModel setting = settings.get(key);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return key;\r
+               case Value:\r
+                       return setting;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public SettingModel get(int modelRow) {\r
+               String key = keys.get(modelRow);\r
+               return settings.get(key);\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/UsersModel.java b/src/com/gitblit/client/UsersModel.java
deleted file mode 100644 (file)
index 2b3c644..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*\r
- * Copyright 2011 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.client;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import javax.swing.table.AbstractTableModel;\r
-\r
-import com.gitblit.models.UserModel;\r
-\r
-/**\r
- * Table model of a list of users.\r
- * \r
- * @author James Moger\r
- * \r
- */\r
-public class UsersModel extends AbstractTableModel {\r
-\r
-       private static final long serialVersionUID = 1L;\r
-\r
-       List<UserModel> list;\r
-\r
-       enum Columns {\r
-               Name;\r
-\r
-               @Override\r
-               public String toString() {\r
-                       return name().replace('_', ' ');\r
-               }\r
-       }\r
-\r
-       public UsersModel() {\r
-               this(new ArrayList<UserModel>());\r
-       }\r
-\r
-       public UsersModel(List<UserModel> users) {\r
-               this.list = users;\r
-               Collections.sort(this.list);\r
-       }\r
-\r
-       @Override\r
-       public int getRowCount() {\r
-               return list.size();\r
-       }\r
-\r
-       @Override\r
-       public int getColumnCount() {\r
-               return Columns.values().length;\r
-       }\r
-\r
-       @Override\r
-       public String getColumnName(int column) {\r
-               Columns col = Columns.values()[column];\r
-               switch (col) {\r
-               case Name:\r
-                       return Translation.get("gb.name");\r
-               }\r
-               return "";\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
-        * \r
-        * @param columnIndex\r
-        *            the column being queried\r
-        * @return the Object.class\r
-        */\r
-       public Class<?> getColumnClass(int columnIndex) {\r
-               return String.class;\r
-       }\r
-\r
-       @Override\r
-       public Object getValueAt(int rowIndex, int columnIndex) {\r
-               UserModel model = list.get(rowIndex);\r
-               Columns col = Columns.values()[columnIndex];\r
-               switch (col) {\r
-               case Name:\r
-                       return model.username;\r
-               }\r
-               return null;\r
-       }\r
-}\r
diff --git a/src/com/gitblit/client/UsersTableModel.java b/src/com/gitblit/client/UsersTableModel.java
new file mode 100644 (file)
index 0000000..57536ad
--- /dev/null
@@ -0,0 +1,97 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.models.UserModel;\r
+\r
+/**\r
+ * Table model of a list of users.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class UsersTableModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<UserModel> list;\r
+\r
+       enum Columns {\r
+               Name;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public UsersTableModel() {\r
+               this(new ArrayList<UserModel>());\r
+       }\r
+\r
+       public UsersTableModel(List<UserModel> users) {\r
+               this.list = users;\r
+               Collections.sort(this.list);\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return list.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Name:\r
+                       return Translation.get("gb.name");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               return String.class;\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               UserModel model = list.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Name:\r
+                       return model.username;\r
+               }\r
+               return null;\r
+       }\r
+}\r
diff --git a/src/com/gitblit/models/ServerSettings.java b/src/com/gitblit/models/ServerSettings.java
new file mode 100644 (file)
index 0000000..47148d3
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.models;\r
+\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+\r
+import com.gitblit.IStoredSettings;\r
+\r
+/**\r
+ * Server settings represents the settings of the Gitblit server including all\r
+ * setting metadata such as name, current value, default value, description, and\r
+ * directives. It is a model class for serialization and presentation, but not\r
+ * for persistence.\r
+ * \r
+ * @author James Moger\r
+ */\r
+public class ServerSettings implements Serializable {\r
+\r
+       private final Map<String, SettingModel> settings;\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public ServerSettings() {\r
+               settings = new TreeMap<String, SettingModel>();\r
+       }\r
+       \r
+       public List<String> getKeys() {\r
+               return new ArrayList<String>(settings.keySet());\r
+       }\r
+\r
+       public void add(SettingModel setting) {\r
+               settings.put(setting.name, setting);\r
+       }\r
+\r
+       public SettingModel get(String key) {\r
+               return settings.get(key);\r
+       }\r
+\r
+       public void updateCurrentValues(IStoredSettings storedSettings) {\r
+               for (String key : storedSettings.getAllKeys(null)) {\r
+                       if (settings.containsKey(key)) {\r
+                               settings.get(key).currentValue = storedSettings.getString(key, "");\r
+                       }\r
+               }\r
+       }\r
+}\r
index b1dc52dd266bfd7896a942c774a16c3270d3ac14..8dfc0fbcf28459caf652e291f24a465dbab4baf3 100644 (file)
@@ -17,12 +17,12 @@ package com.gitblit.models;
 \r
 import java.io.Serializable;\r
 import java.util.Date;\r
-import java.util.HashMap;\r
 import java.util.Map;\r
+import java.util.TreeMap;\r
 \r
 /**\r
  * ServerStatus encapsulates runtime status information about the server\r
- * including the system environment.\r
+ * including some information about the system environment.\r
  * \r
  * @author James Moger\r
  * \r
@@ -33,10 +33,10 @@ public class ServerStatus implements Serializable {
 \r
        public final Date bootDate;\r
        \r
+       public final Map<String, String> systemProperties;\r
+\r
        public final long heapSize;\r
 \r
-       public final Map<String, String> systemProperties;\r
-       \r
        public volatile long heapAllocated;\r
        \r
        public volatile long heapFree;\r
@@ -46,7 +46,7 @@ public class ServerStatus implements Serializable {
                \r
                heapSize = Runtime.getRuntime().maxMemory();\r
                \r
-               systemProperties = new HashMap<String, String>();\r
+               systemProperties = new TreeMap<String, String>();\r
                put("file.encoding");\r
                put("java.home");\r
                put("java.io.tmpdir");\r
index 440dabdb88dbb11a91ddfe515c17eda67b94bf0d..2d409a0ad5f197f07f7e78d0c2a9ce1c01f45cc0 100644 (file)
@@ -29,7 +29,7 @@ import com.gitblit.models.FederationProposal;
 import com.gitblit.models.FederationSet;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.ServerStatus;\r
-import com.gitblit.models.SettingModel;\r
+import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.UserModel;\r
 import com.google.gson.reflect.TypeToken;\r
 \r
@@ -59,9 +59,6 @@ public class RpcUtils {
        private static final Type SETS_TYPE = new TypeToken<Collection<FederationSet>>() {\r
        }.getType();\r
 \r
-       private static final Type SETTINGS_TYPE = new TypeToken<Map<String, SettingModel>>() {\r
-       }.getType();\r
-\r
        /**\r
         * \r
         * @param remoteURL\r
@@ -341,14 +338,13 @@ public class RpcUtils {
         * @param serverUrl\r
         * @param account\r
         * @param password\r
-        * @return an Map<String, SettingModel> object\r
+        * @return an Settings object\r
         * @throws IOException\r
         */\r
-       public static Map<String, SettingModel> getSettings(String serverUrl, String account,\r
-                       char[] password) throws IOException {\r
+       public static ServerSettings getSettings(String serverUrl, String account, char[] password)\r
+                       throws IOException {\r
                String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS);\r
-               Map<String, SettingModel> settings = JsonUtils.retrieveJson(url, SETTINGS_TYPE, account,\r
-                               password);\r
+               ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account, password);\r
                return settings;\r
        }\r
 \r
@@ -363,7 +359,7 @@ public class RpcUtils {
         */\r
        public static ServerStatus getStatus(String serverUrl, String account, char[] password)\r
                        throws IOException {\r
-               String url = asLink(serverUrl, RpcRequest.LIST_SERVER_STATUS);\r
+               String url = asLink(serverUrl, RpcRequest.LIST_STATUS);\r
                ServerStatus status = JsonUtils.retrieveJson(url, ServerStatus.class, account, password);\r
                return status;\r
        }\r
index 3c2f61f985bb7b4c5156d4a03b77fa7c94e0516f..11a340a94d8ae29244882acf558e657bbdc43bee 100644 (file)
@@ -27,8 +27,8 @@ import com.gitblit.models.FederationModel;
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.FederationSet;\r
 import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.ServerStatus;\r
-import com.gitblit.models.SettingModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.RpcUtils;\r
 \r
@@ -207,7 +207,7 @@ public class RpcTests extends TestCase {
        }\r
 \r
        public void testSettings() throws Exception {\r
-               Map<String, SettingModel> settings = RpcUtils.getSettings(url, account, password.toCharArray());\r
+               ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray());\r
                assertTrue("No settings were retrieved!", settings != null);\r
        }\r
        \r