summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/utils
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-10-12 22:14:10 -0400
committerJames Moger <james.moger@gitblit.com>2011-10-12 22:14:10 -0400
commitda0269b4bd57bf90877446d9f991247bc1ad2f64 (patch)
tree96033518957a9d91c831c994033c2be22f7cfadf /src/com/gitblit/utils
parent13b8381bf7082778df572e7918599a41917bfcca (diff)
downloadgitblit-da0269b4bd57bf90877446d9f991247bc1ad2f64.tar.gz
gitblit-da0269b4bd57bf90877446d9f991247bc1ad2f64.zip
RPC Client: Create/Edit Repository & User. Partially working.
Added new request type to retrieve Gitblit settings to implement the password preferences (minLength, storage type) and federation sets.
Diffstat (limited to 'src/com/gitblit/utils')
-rw-r--r--src/com/gitblit/utils/JsonUtils.java19
-rw-r--r--src/com/gitblit/utils/RpcUtils.java61
2 files changed, 72 insertions, 8 deletions
diff --git a/src/com/gitblit/utils/JsonUtils.java b/src/com/gitblit/utils/JsonUtils.java
index 3834c8ed..fee79901 100644
--- a/src/com/gitblit/utils/JsonUtils.java
+++ b/src/com/gitblit/utils/JsonUtils.java
@@ -157,6 +157,25 @@ public class JsonUtils {
}
return gson().fromJson(json, type);
}
+
+ /**
+ * Reads a gson object from the specified url.
+ *
+ * @param url
+ * @param clazz
+ * @param username
+ * @param password
+ * @return the deserialized object
+ * @throws {@link IOException}
+ */
+ public static <X> X retrieveJson(String url, Class<X> clazz, String username, char[] password)
+ throws IOException {
+ String json = retrieveJsonString(url, username, password);
+ if (StringUtils.isEmpty(json)) {
+ return null;
+ }
+ return gson().fromJson(json, clazz);
+ }
/**
* Retrieves a JSON message.
diff --git a/src/com/gitblit/utils/RpcUtils.java b/src/com/gitblit/utils/RpcUtils.java
index 715ecb57..eb28c0f9 100644
--- a/src/com/gitblit/utils/RpcUtils.java
+++ b/src/com/gitblit/utils/RpcUtils.java
@@ -21,9 +21,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import com.gitblit.Constants;
import com.gitblit.Constants.RpcRequest;
+import com.gitblit.IStoredSettings;
import com.gitblit.models.FederationModel;
import com.gitblit.models.FederationProposal;
import com.gitblit.models.FederationSet;
@@ -294,7 +296,7 @@ public class RpcUtils {
List<FederationModel> list = new ArrayList<FederationModel>(registrations);
return list;
}
-
+
/**
* Retrieves the list of federation proposals.
*
@@ -304,15 +306,15 @@ public class RpcUtils {
* @return a collection of FederationProposal objects
* @throws IOException
*/
- public static List<FederationProposal> getFederationProposals(String serverUrl,
- String account, char[] password) throws IOException {
+ public static List<FederationProposal> getFederationProposals(String serverUrl, String account,
+ char[] password) throws IOException {
String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_PROPOSALS);
Collection<FederationProposal> proposals = JsonUtils.retrieveJson(url, PROPOSALS_TYPE,
account, password);
List<FederationProposal> list = new ArrayList<FederationProposal>(proposals);
return list;
}
-
+
/**
* Retrieves the list of federation repository sets.
*
@@ -322,16 +324,32 @@ public class RpcUtils {
* @return a collection of FederationSet objects
* @throws IOException
*/
- public static List<FederationSet> getFederationSets(String serverUrl,
- String account, char[] password) throws IOException {
+ public static List<FederationSet> getFederationSets(String serverUrl, String account,
+ char[] password) throws IOException {
String url = asLink(serverUrl, RpcRequest.LIST_FEDERATION_SETS);
- Collection<FederationSet> sets = JsonUtils.retrieveJson(url, SETS_TYPE,
- account, password);
+ Collection<FederationSet> sets = JsonUtils.retrieveJson(url, SETS_TYPE, account, password);
List<FederationSet> list = new ArrayList<FederationSet>(sets);
return list;
}
/**
+ * Retrieves the settings of the Gitblit server.
+ *
+ * @param serverUrl
+ * @param account
+ * @param password
+ * @return an IStoredSettings object
+ * @throws IOException
+ */
+ public static IStoredSettings getSettings(String serverUrl, String account, char[] password)
+ throws IOException {
+ String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS);
+ Properties props = JsonUtils.retrieveJson(url, Properties.class, account, password);
+ RpcSettings settings = new RpcSettings(props);
+ return settings;
+ }
+
+ /**
* Do the specified administrative action on the Gitblit server.
*
* @param request
@@ -351,4 +369,31 @@ public class RpcUtils {
int resultCode = JsonUtils.sendJsonString(url, json, account, password);
return resultCode == 200;
}
+
+ /**
+ * Settings implementation that wraps a retrieved properties instance. This
+ * class is used for RPC communication.
+ *
+ * @author James Moger
+ *
+ */
+ private static class RpcSettings extends IStoredSettings {
+
+ private final Properties properties = new Properties();
+
+ public RpcSettings(Properties props) {
+ super(RpcSettings.class);
+ properties.putAll(props);
+ }
+
+ @Override
+ protected Properties read() {
+ return properties;
+ }
+
+ @Override
+ public String toString() {
+ return "RpcSettings";
+ }
+ }
}