usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [01/50] [abbrv] usergrid git commit: Fix issue with ApiServerRunner and Java SDK version mismatch.
Date Wed, 17 Aug 2016 21:17:20 GMT
Repository: usergrid
Updated Branches:
  refs/heads/datastax-cass-driver 32782a39b -> 5095891dd


Fix issue with ApiServerRunner and Java SDK version mismatch.


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

Branch: refs/heads/datastax-cass-driver
Commit: acd8719758dbe24ea446f28130cc39aef9c24ed7
Parents: 92554a4
Author: Michael Russo <mrusso@apigee.com>
Authored: Tue Jul 26 14:58:05 2016 -0700
Committer: Michael Russo <mrusso@apigee.com>
Committed: Tue Jul 26 14:58:05 2016 -0700

----------------------------------------------------------------------
 .../java/client/model/UsergridEntity.java       |  2 +-
 stack/query-validator/pom.xml                   |  4 +-
 .../query/validator/ApiServerRunner.java        | 89 +++++++-------------
 3 files changed, 33 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/acd87197/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 e3dbb77..3444de0 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
@@ -412,7 +412,7 @@ public class UsergridEntity {
     }
 
     @JsonAnyGetter @NotNull
-    private Map<String, JsonNode> getProperties() {
+    public Map<String, JsonNode> getProperties() {
         return this.properties;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/acd87197/stack/query-validator/pom.xml
----------------------------------------------------------------------
diff --git a/stack/query-validator/pom.xml b/stack/query-validator/pom.xml
index 49fe554..4355986 100644
--- a/stack/query-validator/pom.xml
+++ b/stack/query-validator/pom.xml
@@ -21,7 +21,7 @@
     <parent>
         <groupId>org.apache.usergrid</groupId>
         <artifactId>usergrid</artifactId>
-        <version>2.1.1-SNAPSHOT</version>
+        <version>2.2.0-SNAPSHOT</version>
     </parent>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -253,7 +253,7 @@
         <dependency>
             <groupId>org.apache.usergrid</groupId>
             <artifactId>usergrid-java-client</artifactId>
-            <version>0.0.10-SNAPSHOT</version>
+            <version>${project.version}</version>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/usergrid/blob/acd87197/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
----------------------------------------------------------------------
diff --git a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
index b06e40b..7c4d3e5 100644
--- a/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
+++ b/stack/query-validator/src/main/java/org/apache/usergrid/query/validator/ApiServerRunner.java
@@ -17,20 +17,17 @@
 package org.apache.usergrid.query.validator;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
+
+import java.util.*;
 import java.util.logging.Logger;
-import org.apache.commons.lang.StringUtils;
+import org.apache.usergrid.java.client.UsergridClient;
+import org.apache.usergrid.java.client.auth.UsergridUserAuth;
+import org.apache.usergrid.java.client.model.UsergridEntity;
+import org.apache.usergrid.java.client.query.UsergridQuery;
+import org.apache.usergrid.java.client.response.UsergridResponse;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.Schema;
-import org.springframework.http.HttpMethod;
 import org.springframework.stereotype.Component;
-import org.apache.usergrid.java.client.Client;
-import org.apache.usergrid.java.client.response.ApiResponse;
-import static org.apache.usergrid.java.client.utils.ObjectUtils.isEmpty;
 
 
 /**
@@ -40,7 +37,7 @@ import static org.apache.usergrid.java.client.utils.ObjectUtils.isEmpty;
 public class ApiServerRunner implements QueryRunner {
 
     private Logger logger = Logger.getLogger(SqliteRunner.class.getName());
-    private Client client;
+    private UsergridClient client;
 
     private String org;
     private String app;
@@ -52,62 +49,38 @@ public class ApiServerRunner implements QueryRunner {
 
     @Override
     public boolean setup() {
-        client = new Client(getOrg(), getApp()).withApiUrl(getBaseUri());
-        String accessToken = authorize(email, password);
-        if(!StringUtils.isEmpty(accessToken))
-            client.setAccessToken(accessToken);
-        return insertDatas();
-    }
 
-    public String authorize(String email, String password) {
-        String accessToken = null;
-        Map<String, Object> formData = new HashMap<String, Object>();
-        formData.put("grant_type", "password");
-        formData.put("username", email);
-        formData.put("password", password);
-        ApiResponse response = client.apiRequest(HttpMethod.POST, null, formData,
-                "management", "token");
-        if (!isEmpty(response.getAccessToken())) {
-            accessToken = response.getAccessToken();
-            logger.info("Access token: " + accessToken);
-        } else {
-            logger.info("Response: " + response);
-        }
-        return accessToken;
+        client = new UsergridClient(getOrg(), getApp(), getBaseUri());
+        UsergridUserAuth usergridUserAuth = new UsergridUserAuth(email, password);
+        client.authenticateUser(usergridUserAuth);
+
+        return insertDatas();
     }
 
     public boolean insertDatas() {
-       List<org.apache.usergrid.java.client.entities.Entity> clientEntities = getEntitiesForClient(getEntities());
-       for(org.apache.usergrid.java.client.entities.Entity entity : clientEntities) {
-           ApiResponse response = client.createEntity(entity);
-           if( response == null || !StringUtils.isEmpty(response.getError()) ) {
-               logger.log(Level.SEVERE, response.getErrorDescription());
-               //throw new RuntimeException(response.getErrorDescription());
-           } else {
-               logger.log(Level.INFO, response.toString());
-           }
-       }
+       List<UsergridEntity> clientEntities = getEntitiesForClient(getEntities());
+       client.POST(clientEntities);
        return true;
     }
 
-    private List<org.apache.usergrid.java.client.entities.Entity> getEntitiesForClient(List<Entity>
entities) {
-        List<org.apache.usergrid.java.client.entities.Entity> clientEntities = new
ArrayList<org.apache.usergrid.java.client.entities.Entity>();
+    private List<UsergridEntity> getEntitiesForClient(List<Entity> entities)
{
+        List<UsergridEntity> clientEntities = new ArrayList<>();
         for(Entity entity : entities) {
-            org.apache.usergrid.java.client.entities.Entity clientEntity = new org.apache.usergrid.java.client.entities.Entity();
-            clientEntity.setType(entity.getType());
+            UsergridEntity clientEntity = new UsergridEntity(entity.getType());
+
             Map<String, Object> properties = Schema.getDefaultSchema().getEntityProperties(entity);
             for(String key : properties.keySet()) {
                 Object value = entity.getProperty(key);
                 if( value instanceof String )
-                    clientEntity.setProperty(key,(String)value );
+                    clientEntity.putProperty(key,(String)value );
                 else if( value instanceof Long )
-                    clientEntity.setProperty(key,(Long)value );
+                    clientEntity.putProperty(key,(Long)value );
                 else if( value instanceof Integer )
-                    clientEntity.setProperty(key,(Integer)value );
+                    clientEntity.putProperty(key,(Integer)value );
                 else if( value instanceof Float )
-                    clientEntity.setProperty(key,(Float)value );
+                    clientEntity.putProperty(key,(Float)value );
                 else if( value instanceof Boolean )
-                    clientEntity.setProperty(key,(Boolean)value );
+                    clientEntity.putProperty(key,(Boolean)value );
             }
             clientEntities.add(clientEntity);
         }
@@ -121,19 +94,17 @@ public class ApiServerRunner implements QueryRunner {
 
     @Override
     public List<Entity> execute(String query, int limit) {
-        Map<String, Object> params = new HashMap<String, Object>();
-        params.put("ql", query);
-        params.put("limit", limit);
-        ApiResponse response = client.apiRequest(HttpMethod.GET, params, null, getOrg(),
getApp(), getCollection());
+        UsergridQuery usergridQuery = new UsergridQuery().ql(query).limit(limit).type(getCollection());
+        UsergridResponse response = client.GET(usergridQuery);
         List<Entity> entities = new ArrayList<Entity>();
         if( response.getEntities() == null )
             return entities;
 
-        for(org.apache.usergrid.java.client.entities.Entity clientEntitity : response.getEntities())
{
+        for(UsergridEntity clientEntity : response.getEntities()) {
             Entity entity = new QueryEntity();
-            entity.setUuid(clientEntitity.getUuid());
-            entity.setType(clientEntitity.getType());
-            Map<String, JsonNode> values = clientEntitity.getProperties();
+            entity.setUuid(UUID.fromString(clientEntity.getUuid()));
+            entity.setType(clientEntity.getType());
+            Map<String, JsonNode> values = clientEntity.getProperties();
             for( String key : values.keySet() ) {
                 JsonNode node = values.get(key);
                 if( node.isBoolean() ) {


Mime
View raw message