juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject incubator-juneau git commit: Additional params() methods.
Date Wed, 05 Apr 2017 20:15:00 GMT
Repository: incubator-juneau
Updated Branches:
  refs/heads/master 6f02183cb -> 8827e0b8b


Additional params() methods.

Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/8827e0b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/8827e0b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/8827e0b8

Branch: refs/heads/master
Commit: 8827e0b8b2b6514e807c3d2af9ba2635ee41a99c
Parents: 6f02183
Author: JamesBognar <jamesbognar@apache.org>
Authored: Wed Apr 5 16:14:57 2017 -0400
Committer: JamesBognar <jamesbognar@apache.org>
Committed: Wed Apr 5 16:14:57 2017 -0400

----------------------------------------------------------------------
 .../org/apache/juneau/rest/client/RestCall.java | 77 ++++++++++++++++++++
 1 file changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/8827e0b8/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
----------------------------------------------------------------------
diff --git a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
index 6a94723..5587f7b 100644
--- a/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
+++ b/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestCall.java
@@ -176,6 +176,83 @@ public final class RestCall {
 	}
 
 	/**
+	 * Adds parameters to the URI query.
+	 *
+	 * @param params The parameters.  Values are converted to a string using UON notation.
+	 * @return This object (for method chaining).
+	 * @throws RestCallException
+	 */
+	public RestCall params(Map<String,Object> params) throws RestCallException {
+		for (Map.Entry<String,Object> p : params.entrySet())
+			uriBuilder.addParameter(p.getKey(), client.getUrlEncodingSerializer().serializeUrlPart(p.getValue()));
+		return this;
+	}
+
+	/**
+	 * Adds a parameter to the URI query if the parameter value is not <jk>null</jk>.
+	 *
+	 * @param name The parameter name.
+	 * @param value The parameter value converted to a string using UON notation.
+	 * @return This object (for method chaining).
+	 * @throws RestCallException
+	 */
+	public RestCall paramIfNN(String name, Object value) throws RestCallException {
+		if (value != null)
+			uriBuilder.addParameter(name, client.getUrlEncodingSerializer().serializeUrlPart(value));
+		return this;
+	}
+
+	/**
+	 * Same as {@link #params(Map)} but ignores values that are <jk>null</jk>.
+	 *
+	 * @param params The parameters.  Values are converted to a string using UON notation.
+	 * @return This object (for method chaining).
+	 * @throws RestCallException
+	 */
+	public RestCall paramsIfNN(Map<String,Object> params) throws RestCallException {
+		if (params != null) {
+			for (Map.Entry<String,Object> e : params.entrySet()) {
+				Object value = e.getValue();
+				if (value != null)
+					uriBuilder.addParameter(e.getKey(), client.getUrlEncodingSerializer().serializeUrlPart(value));
+			}
+		}
+		return this;
+	}
+
+	/**
+	 * Adds a parameter to the URI query if the parameter value is not <jk>null</jk>
or an empty string.
+	 *
+	 * @param name The parameter name.
+	 * @param value The parameter value converted to a string using UON notation.
+	 * @return This object (for method chaining).
+	 * @throws RestCallException
+	 */
+	public RestCall paramIfNE(String name, Object value) throws RestCallException {
+		if (! StringUtils.isEmpty(value))
+			uriBuilder.addParameter(name, client.getUrlEncodingSerializer().serializeUrlPart(value));
+		return this;
+	}
+
+	/**
+	 * Same as {@link #params(Map)} but ignores values that are <jk>null</jk> or
empty strings.
+	 *
+	 * @param params The parameters.  Values are converted to a string using UON notation.
+	 * @return This object (for method chaining).
+	 * @throws RestCallException
+	 */
+	public RestCall paramIfNE(Map<String,Object> params) throws RestCallException {
+		if (params != null) {
+			for (Map.Entry<String,Object> e : params.entrySet()) {
+				Object value = e.getValue();
+				if (! StringUtils.isEmpty(value))
+					uriBuilder.addParameter(e.getKey(), client.getUrlEncodingSerializer().serializeUrlPart(value));
+			}
+		}
+		return this;
+	}
+
+	/**
 	 * Sets a custom URI query.
 	 *
 	 * @param query The new URI query string.


Mime
View raw message