From 4c835e61e8ea2d5af2acf0c85c3c1f0d06f419df Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 26 Oct 2011 17:19:55 -0400
Subject: [PATCH] Documentation.
---
src/com/gitblit/client/GitblitClient.java | 83 ++++++++++++++++++++++++++++++++++-------
1 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/src/com/gitblit/client/GitblitModel.java b/src/com/gitblit/client/GitblitClient.java
similarity index 69%
rename from src/com/gitblit/client/GitblitModel.java
rename to src/com/gitblit/client/GitblitClient.java
index 92b0b1c..9f4dd3e 100644
--- a/src/com/gitblit/client/GitblitModel.java
+++ b/src/com/gitblit/client/GitblitClient.java
@@ -23,14 +23,25 @@
import java.util.Map;
import com.gitblit.GitBlitException.ForbiddenException;
-import com.gitblit.IStoredSettings;
+import com.gitblit.GitBlitException.NotAllowedException;
+import com.gitblit.GitBlitException.UnauthorizedException;
+import com.gitblit.GitBlitException.UnknownRequestException;
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 +51,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 +63,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 +79,52 @@
refreshRepositories();
try {
- settings = RpcUtils.getSettings(url, account, password);
refreshUsers();
- refreshFederationRegistrations();
- isAdmin = true;
+ refreshSettings();
+ allowManagement = true;
+ } catch (UnauthorizedException e) {
} catch (ForbiddenException e) {
+ } catch (NotAllowedException e) {
+ } catch (UnknownRequestException e) {
} catch (IOException e) {
- System.err.println(e.getMessage());
+ e.printStackTrace();
}
+
+ try {
+ refreshStatus();
+ allowAdministration = true;
+ } catch (UnauthorizedException e) {
+ } catch (ForbiddenException e) {
+ } catch (NotAllowedException e) {
+ } catch (UnknownRequestException e) {
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
}
- 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 +141,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 +184,7 @@
}
public List<String> getFederationSets() {
- return settings.getStrings(Keys.federation.sets);
+ return settings.get(Keys.federation.sets).getStrings();
}
public List<RepositoryModel> getRepositories() {
@@ -177,4 +228,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