usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [13/15] usergrid git commit: Updates. See commit details.
Date Thu, 19 May 2016 17:17:27 GMT
Updates.  See commit details.

Added default constructors to some classes.
Added @JsonProperty annotations to some constructor methods.
Added UsergridEntity.toPrettyString() for constructing a pretty printed Json string.
Fixed UsergridResponse.fromException method to check for null.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/9cccc908
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/9cccc908
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/9cccc908

Branch: refs/heads/master
Commit: 9cccc9089078559e0860019f52c87e57d76fb432
Parents: fb35388
Author: Robert Walsh <rjwalsh1985@gmail.com>
Authored: Fri May 13 11:50:15 2016 -0500
Committer: Robert Walsh <rjwalsh1985@gmail.com>
Committed: Fri May 13 11:50:15 2016 -0500

----------------------------------------------------------------------
 .../java/client/UsergridClientConfig.java       |   3 +++
 .../usergrid/java/client/UsergridRequest.java   |   2 ++
 .../java/client/auth/UsergridAppAuth.java       |   7 ++++++-
 .../usergrid/java/client/auth/UsergridAuth.java |   5 +++--
 .../java/client/auth/UsergridUserAuth.java      |   8 +++++++-
 .../client/exception/UsergridException.java     |   2 ++
 .../java/client/model/UsergridEntity.java       |   3 ++-
 .../java/client/model/UsergridUser.java         |   5 +++--
 .../java/client/response/UsergridResponse.java  |  12 ++++++++++--
 .../usergrid/java/client/utils/JsonUtils.java   |  18 ++++++++++++++++++
 sdks/java/usergrid-java-client-2.1.0.jar        | Bin 1991588 -> 1992239 bytes
 11 files changed, 56 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
index b27d914..f12f9ec 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridClientConfig.java
@@ -37,6 +37,9 @@ public class UsergridClientConfig {
 
     @Nullable public UsergridAppAuth appAuth = null;
 
+    @SuppressWarnings("unused")
+    private UsergridClientConfig() {}
+
     public UsergridClientConfig(@NotNull final String orgId, @NotNull final String appId)
{
         this.orgId = orgId;
         this.appId = appId;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
index 0ac29d6..b16783e 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/UsergridRequest.java
@@ -80,6 +80,8 @@ public class UsergridRequest {
     public String[] getPathSegments() { return pathSegments; }
     public void setPathSegments(@Nullable final String[] pathSegments) { this.pathSegments
= pathSegments; }
 
+    private UsergridRequest() {}
+
     public UsergridRequest(@NotNull final UsergridHttpMethod method,
                            @NotNull final MediaType contentType,
                            @NotNull final String url,

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
index 3ad7251..a7ac64d 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAppAuth.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.java.client.auth;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.HashMap;
@@ -42,7 +43,11 @@ public class UsergridAppAuth extends UsergridAuth {
         return credentials;
     }
 
-    public UsergridAppAuth(@NotNull final String clientId, @NotNull final String clientSecret)
{
+    public UsergridAppAuth() {
+        this("","");
+    }
+
+    public UsergridAppAuth(@JsonProperty("clientId") @NotNull final String clientId, @JsonProperty("clientSecret")
@NotNull final String clientSecret) {
         super();
         this.clientId = clientId;
         this.clientSecret = clientSecret;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
index 81d9187..94b4809 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridAuth.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.java.client.auth;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -30,12 +31,12 @@ public class UsergridAuth {
 
     public UsergridAuth() { }
 
-    public UsergridAuth(@Nullable final String accessToken) {
+    public UsergridAuth(@JsonProperty("accessToken") @Nullable final String accessToken)
{
         this.usingToken = true;
         setAccessToken(accessToken);
     }
 
-    public UsergridAuth(@Nullable final String accessToken, @Nullable final Long expiry)
{
+    public UsergridAuth(@JsonProperty("accessToken") @Nullable final String accessToken,
@JsonProperty("expiry") @Nullable final Long expiry) {
         this.usingToken = true;
         setAccessToken(accessToken);
         setExpiry(expiry);

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
index 961be70..e1831c2 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/auth/UsergridUserAuth.java
@@ -16,6 +16,8 @@
  */
 package org.apache.usergrid.java.client.auth;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.usergrid.java.client.model.UsergridUser;
 import org.jetbrains.annotations.NotNull;
 
 import java.util.HashMap;
@@ -42,7 +44,11 @@ public class UsergridUserAuth extends UsergridAuth {
         return credentials;
     }
 
-    public UsergridUserAuth(@NotNull final String username, @NotNull final String password)
{
+    public UsergridUserAuth() {
+        this("","");
+    }
+
+    public UsergridUserAuth(@JsonProperty("username") @NotNull final String username, @JsonProperty("password")
@NotNull final String password) {
         super();
         this.username = username;
         this.password = password;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/UsergridException.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/UsergridException.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/UsergridException.java
index a9b0cf7..ff30a0d 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/UsergridException.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/exception/UsergridException.java
@@ -28,6 +28,8 @@ public class UsergridException extends RuntimeException {
     }
     public void setResponseCode(final int responseCode) { this.responseCode = responseCode;
}
 
+    private UsergridException() {}
+
     public UsergridException(@NotNull final String message) {
         super(message);
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridEntity.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridEntity.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridEntity.java
index e7af748..e3dbb77 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridEntity.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridEntity.java
@@ -100,11 +100,12 @@ public class UsergridEntity {
     @NotNull @Override public String toString() {
         return toJsonString(this);
     }
+    @NotNull public String toPrettyString() { return toPrettyJsonString(this); }
     @NotNull public JsonNode toJsonObjectValue() {
         return toJsonNode(this);
     }
     @SuppressWarnings("unchecked")
-    @NotNull public Map<String,?> toMapValue() { return entityUpdateMapper.convertValue(this,Map.class);
}
+    @NotNull public Map<String,?> toMapValue() { return toMap(this); }
 
     @JsonIgnore
     public boolean isUser() { return (this instanceof UsergridUser || this.getType().equalsIgnoreCase(UsergridUser.USER_ENTITY_TYPE));
}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridUser.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridUser.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridUser.java
index 9a5bd86..f967e46 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridUser.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/model/UsergridUser.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.java.client.model;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import org.apache.usergrid.java.client.Usergrid;
 import org.apache.usergrid.java.client.UsergridClient;
@@ -85,8 +86,8 @@ public class UsergridUser extends UsergridEntity {
     public boolean isDisabled() { return this.disabled; }
     public void setDisabled(final boolean disabled) { this.disabled = disabled; }
 
-    @Nullable public UsergridUserAuth getUserAuth() { return this.userAuth; }
-    public void setUserAuth(@Nullable final UsergridUserAuth userAuth) { this.userAuth =
userAuth; }
+    @JsonIgnore @Nullable public UsergridUserAuth getUserAuth() { return this.userAuth; }
+    @JsonIgnore public void setUserAuth(@Nullable final UsergridUserAuth userAuth) { this.userAuth
= userAuth; }
 
     @Nullable
     public String uuidOrUsername() {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/response/UsergridResponse.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/UsergridResponse.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/UsergridResponse.java
index 8618d94..ee649c4 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/response/UsergridResponse.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/response/UsergridResponse.java
@@ -183,9 +183,17 @@ public class UsergridResponse {
 
     @NotNull
     public static UsergridResponse fromException(@Nullable final UsergridClient client, @NotNull
final Exception ex) {
-        UsergridResponse response = new UsergridResponse();
+        final UsergridResponse response = new UsergridResponse();
         response.client = client;
-        response.responseError = new UsergridResponseError(ex.getClass().toString(), ex.getMessage(),
ex.getCause().toString());
+        final UsergridResponseError responseError = new UsergridResponseError();
+        responseError.setErrorDescription(ex.getMessage());
+        if( ex.getClass() != null ) {
+            responseError.setErrorName(ex.getClass().toString());
+        }
+        if( ex.getCause() != null ) {
+            responseError.setErrorException(ex.getCause().toString());
+        }
+        response.responseError = responseError;
         return response;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
index d2f43fb..dc1514b 100644
--- a/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
+++ b/sdks/java/src/main/java/org/apache/usergrid/java/client/utils/JsonUtils.java
@@ -82,11 +82,29 @@ public final class JsonUtils {
     }
 
     @NotNull
+    public static String toPrettyJsonString(@NotNull final Object obj) {
+        try {
+            return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
+        } catch (JsonGenerationException e) {
+            throw new UsergridException("Unable to generate json", e);
+        } catch (JsonMappingException e) {
+            throw new UsergridException("Unable to map json", e);
+        } catch (IOException e) {
+            throw new UsergridException("IO error", e);
+        }
+    }
+
+    @NotNull
     public static JsonNode toJsonNode(@NotNull final Object obj) {
         return mapper.convertValue(obj, JsonNode.class);
     }
 
     @NotNull
+    public static Map toMap(@NotNull final Object obj) {
+        return mapper.convertValue(obj,Map.class);
+    }
+
+    @NotNull
     public static <T> T fromJsonNode(@NotNull final JsonNode json, @NotNull final Class<T>
c) {
         try {
             JsonParser jp = json.traverse();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/9cccc908/sdks/java/usergrid-java-client-2.1.0.jar
----------------------------------------------------------------------
diff --git a/sdks/java/usergrid-java-client-2.1.0.jar b/sdks/java/usergrid-java-client-2.1.0.jar
index ce5a1e6..733839e 100644
Binary files a/sdks/java/usergrid-java-client-2.1.0.jar and b/sdks/java/usergrid-java-client-2.1.0.jar
differ


Mime
View raw message