From c05535c2a7e833c5e831e3774b4440d6459918dd Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 26 Oct 2011 17:07:11 -0400
Subject: [PATCH] Documentation.
---
src/com/gitblit/client/GitblitClient.java | 75 +++++++++++++++++++++++++++++++------
1 files changed, 62 insertions(+), 13 deletions(-)
diff --git a/src/com/gitblit/client/GitblitModel.java b/src/com/gitblit/client/GitblitClient.java
similarity index 72%
rename from src/com/gitblit/client/GitblitModel.java
rename to src/com/gitblit/client/GitblitClient.java
index 92b0b1c..761283e 100644
--- a/src/com/gitblit/client/GitblitModel.java
+++ b/src/com/gitblit/client/GitblitClient.java
@@ -23,14 +23,23 @@
import java.util.Map;
import com.gitblit.GitBlitException.ForbiddenException;
-import com.gitblit.IStoredSettings;
+import com.gitblit.GitBlitException.UnauthorizedException;
import com.gitblit.Keys;
import com.gitblit.models.FederationModel;
import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.ServerSettings;
+import com.gitblit.models.ServerStatus;
import com.gitblit.models.UserModel;
import com.gitblit.utils.RpcUtils;
-public class GitblitModel implements Serializable {
+/**
+ * GitblitClient is a object that retrieves data from a Gitblit server, caches
+ * it for local operations, and allows updating or creating Gitblit objects.
+ *
+ * @author James Moger
+ *
+ */
+public class GitblitClient implements Serializable {
private static final long serialVersionUID = 1L;
@@ -40,9 +49,11 @@
private final char[] password;
- private volatile boolean isAdmin;
+ private volatile boolean allowManagement;
- private volatile IStoredSettings settings;
+ private volatile boolean allowAdministration;
+
+ private volatile ServerSettings settings;
private final List<RepositoryModel> allRepositories;
@@ -50,7 +61,9 @@
private final List<FederationModel> federationRegistrations;
- public GitblitModel(String url, String account, char[] password) {
+ private ServerStatus status;
+
+ public GitblitClient(String url, String account, char[] password) {
this.url = url;
this.account = account;
this.password = password;
@@ -64,26 +77,48 @@
refreshRepositories();
try {
- settings = RpcUtils.getSettings(url, account, password);
refreshUsers();
- refreshFederationRegistrations();
- isAdmin = true;
+ allowManagement = true;
+ } catch (UnauthorizedException e) {
} catch (ForbiddenException e) {
} catch (IOException e) {
System.err.println(e.getMessage());
}
+
+ try {
+ refreshSettings();
+ refreshStatus();
+ allowAdministration = true;
+ } catch (UnauthorizedException e) {
+ } catch (ForbiddenException e) {
+ } catch (IOException e) {
+ System.err.println(e.getMessage());
+ }
+
}
- public boolean allowAdmin() {
- return isAdmin;
+ public boolean allowManagement() {
+ return allowManagement;
+ }
+
+ public boolean allowAdministration() {
+ return allowAdministration;
}
public boolean isOwner(RepositoryModel model) {
- return account.equalsIgnoreCase(model.owner);
+ return account != null && account.equalsIgnoreCase(model.owner);
}
- public IStoredSettings getSettings() {
+ public ServerSettings getSettings() {
return settings;
+ }
+
+ public ServerStatus getStatus() {
+ return status;
+ }
+
+ public String getSettingDescription(String key) {
+ return settings.get(key).description;
}
public List<RepositoryModel> refreshRepositories() throws IOException {
@@ -100,6 +135,16 @@
allUsers.clear();
allUsers.addAll(users);
return allUsers;
+ }
+
+ public ServerSettings refreshSettings() throws IOException {
+ settings = RpcUtils.getSettings(url, account, password);
+ return settings;
+ }
+
+ public ServerStatus refreshStatus() throws IOException {
+ status = RpcUtils.getStatus(url, account, password);
+ return status;
}
public List<FederationModel> refreshFederationRegistrations() throws IOException {
@@ -133,7 +178,7 @@
}
public List<String> getFederationSets() {
- return settings.getStrings(Keys.federation.sets);
+ return settings.get(Keys.federation.sets).getStrings();
}
public List<RepositoryModel> getRepositories() {
@@ -177,4 +222,8 @@
public boolean deleteUser(UserModel user) throws IOException {
return RpcUtils.deleteUser(user, url, account, password);
}
+
+ public boolean updateSettings(Map<String, String> newSettings) throws IOException {
+ return RpcUtils.updateSettings(newSettings, url, account, password);
+ }
}
--
Gitblit v1.9.1