usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [1/2] incubator-usergrid git commit: Removed variables and put everything into the dynamic properties. Made it so that dynamic properties can be queried out to give the organization values. Added way to get organization specific values out so that we don
Date Fri, 12 Dec 2014 19:35:51 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/UG-rest-test-framework-overhaul 39199e75a -> 64d9b8159


Removed variables and put everything into the dynamic properties.
Made it so that dynamic properties can be queried out to give the organization values.
Added way to get organization specific values out so that we don't get the entire response
back.


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

Branch: refs/heads/UG-rest-test-framework-overhaul
Commit: 8bf8dcccc07e39eca6e42d1062ebfa68fbcdffeb
Parents: b030d89
Author: grey <greyes@apigee.com>
Authored: Fri Dec 12 11:35:06 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Fri Dec 12 11:35:06 2014 -0800

----------------------------------------------------------------------
 .../endpoints/mgmt/OrgResource.java             |  14 +-
 .../test/resource2point0/model/ApiResponse.java |   8 +
 .../rest/test/resource2point0/model/Entity.java | 207 +++++++++----------
 .../resource2point0/model/Organization.java     |  81 ++------
 4 files changed, 142 insertions(+), 168 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bf8dccc/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
index 1d19719..ef0720a 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/mgmt/OrgResource.java
@@ -18,6 +18,7 @@
 package org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt;
 
 
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
@@ -53,9 +54,18 @@ public class OrgResource  extends NamedResource {
     //TODO: why take in a map? Just use base resource and call post from there,
     //TODO: Why ApiResponse when we could just type what we expect back.
     public Organization post(Organization organization){
+        ApiResponse response = getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept(
MediaType.APPLICATION_JSON )
+                     .post( ApiResponse.class,organization );
 
-        return getResource().type( MediaType.APPLICATION_JSON_TYPE ).accept( MediaType.APPLICATION_JSON
)
-                            .post( Organization.class,organization );
+        LinkedHashMap linkedHashMap = ( LinkedHashMap ) response.getData();
+        //organization.putAll( response.getData());
+        //Organization organization1 //= ( Organization ) linkedHashMap.get( "organization"
); //.get( "organization" );
+
+        organization.putAll( ( Map<? extends String, ?> ) linkedHashMap.get("organization")
);
+       // organization.pu
+       // organization.putAll( linkedHashMap.get( "organization" ) );
+
+        return organization;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bf8dccc/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
index de61349..a49f4c2 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/ApiResponse.java
@@ -46,6 +46,7 @@ public class ApiResponse<Entity> {
 
     private String path;
     private String uri;
+    private Object data;
     private String status;
     private long timestamp;
     private List<Entity> entities;
@@ -202,6 +203,13 @@ public class ApiResponse<Entity> {
         this.cursor = cursor;
     }
 
+    @JsonSerialize( include = Inclusion.NON_NULL )
+    public Object getData() {
+        return data;
+    }
 
+    public void setData ( Object data ) {
+        this.data = data;
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bf8dccc/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
index 5ed47d3..9063787 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Entity.java
@@ -35,6 +35,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.apache.usergrid.persistence.EntityFactory;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.test.resource2point0.endpoints.Collection;
 
 import com.fasterxml.jackson.annotation.JsonAnyGetter;
@@ -55,21 +56,11 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
  */
 
 @XmlRootElement
-public class Entity implements Serializable {
+public class Entity implements Serializable, Map<String,Object> {
 
-    protected UUID uuid;
-
-    protected Long created;
-
-    protected Long modified;
-
-    protected String type;
 
     protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>(
String.CASE_INSENSITIVE_ORDER );
 
-    protected Map<String, Set<Object>> dynamic_sets = new TreeMap<String,
Set<Object>>( String.CASE_INSENSITIVE_ORDER );
-
-
     private Collection targetResource;
 
 
@@ -83,34 +74,31 @@ public class Entity implements Serializable {
     }
 
 
-    @EntityProperty( required = true, mutable = false, basic = true, indexed = false )
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
-    public UUID getUuid() {
-        return uuid;
+    public UUID getUuid(){
+        return  UUID.fromString( (String) get("uuid") ); //get( "uuid" );
     }
 
 
     public void setUuid( UUID uuid ) {
-        this.uuid = uuid;
+        put( "uuid", uuid );
     }
 
-
-    @EntityProperty( required = true, mutable = false, basic = true, indexed = false )
+    //TODO: see if this is needed
+    //    @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getType() {
-        return type;
-        //return Schema.getDefaultSchema().getEntityType( this.getClass() );
+        return (String) get( "type" );
     }
 
 
     public void setType( String type ) {
-        this.type = type;
+        put("type",type);
     }
 
 
-    @EntityProperty( indexed = true, required = true, mutable = false )
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public Long getCreated() {
-        return created;
+        return (Long) get( "created" );
     }
 
 
@@ -118,14 +106,14 @@ public class Entity implements Serializable {
         if ( created == null ) {
             created = System.currentTimeMillis();
         }
-        this.created = created;
+        put( "created", created );
     }
 
 
     @EntityProperty( indexed = true, required = true, mutable = true )
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public Long getModified() {
-        return modified;
+        return (Long) get( "modified" );
     }
 
 
@@ -133,7 +121,7 @@ public class Entity implements Serializable {
         if ( modified == null ) {
             modified = System.currentTimeMillis();
         }
-        this.modified = modified;
+        put( "modified", modified );
     }
 
 
@@ -146,7 +134,7 @@ public class Entity implements Serializable {
             return value.toString();
         }
 
-        return ( String ) value;
+        return (String) get( "name" );
     }
 
 
@@ -157,36 +145,35 @@ public class Entity implements Serializable {
 
 
     public final Object getProperty( String propertyName ) {
-        return dynamic_properties.get( propertyName );
+        return get( propertyName );
     }
 
-
-    public final void setProperty( String propertyName, Object propertyValue ) {
-        if ( propertyValue == null || propertyValue.equals( "" ) ) {
-            if ( dynamic_properties.containsKey( propertyName ) ) {
-                dynamic_properties.remove( propertyName );
-            }
-        }
-        else {
-            dynamic_properties.put( propertyName, propertyValue );
-        }
-    }
+//
+//    public final void setProperty( String propertyName, Object propertyValue ) {
+//        if ( propertyValue == null || propertyValue.equals( "" ) ) {
+//            if ( containsKey( propertyName ) ) {
+//                remove( propertyName );
+//            }
+//        }
+//        else {
+//            put( propertyName, propertyValue );
+//        }
+//    }
 
 
     public void setProperties( Map<String, Object> properties ) {
-        dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER
);
-        addProperties( properties );
+        putAll( properties );
     }
 
 
-    public void addProperties( Map<String, Object> properties ) {
-        if ( properties == null ) {
-            return;
-        }
-        for ( Map.Entry<String, Object> entry : properties.entrySet() ) {
-            setProperty( entry.getKey(), entry.getValue() );
-        }
-    }
+//    public void addProperties( Map<String, Object> properties ) {
+//        if ( properties == null ) {
+//            return;
+//        }
+//        for ( Map.Entry<String, Object> entry : properties.entrySet() ) {
+//            setProperty( entry.getKey(), entry.getValue() );
+//        }
+//    }
 
 
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
@@ -211,7 +198,7 @@ public class Entity implements Serializable {
 
 
     public <T> T getDataset( String property, String key ) {
-        Object md = dynamic_properties.get( property );
+        Object md = get( property );
         if ( md == null ) {
             return null;
         }
@@ -227,10 +214,10 @@ public class Entity implements Serializable {
         if ( key == null ) {
             return;
         }
-        Object md = dynamic_properties.get( property );
+        Object md = get( property );
         if ( !( md instanceof Map<?, ?> ) ) {
             md = new HashMap<String, T>();
-            dynamic_properties.put( property, md );
+            put( property, md );
         }
         @SuppressWarnings( "unchecked" ) Map<String, T> metadata = ( Map<String,
T> ) md;
         metadata.put( key, value );
@@ -238,10 +225,10 @@ public class Entity implements Serializable {
 
 
     public <T> void mergeDataset( String property, Map<String, T> new_metadata
) {
-        Object md = dynamic_properties.get( property );
+        Object md = get( property );
         if ( !( md instanceof Map<?, ?> ) ) {
             md = new HashMap<String, T>();
-            dynamic_properties.put( property, md );
+            put( property, md );
         }
         @SuppressWarnings( "unchecked" ) Map<String, T> metadata = ( Map<String,
T> ) md;
         metadata.putAll( new_metadata );
@@ -249,7 +236,7 @@ public class Entity implements Serializable {
 
 
     public void clearDataset( String property ) {
-        dynamic_properties.remove( property );
+        remove( property );
     }
 
 
@@ -283,12 +270,12 @@ public class Entity implements Serializable {
     @JsonAnySetter
     public void setDynamicProperty( String key, Object value ) {
         if ( value == null || value.equals( "" ) ) {
-            if ( dynamic_properties.containsKey( key ) ) {
-                dynamic_properties.remove( key );
+            if ( containsKey( key ) ) {
+                remove( key );
             }
         }
         else {
-            dynamic_properties.put( key, value );
+            put( key, value );
         }
     }
 
@@ -298,65 +285,75 @@ public class Entity implements Serializable {
         return dynamic_properties;
     }
 
+    @Override
+    public int size() {
+        return getDynamicProperties().size();
+    }
 
-    public final int compareTo( org.apache.usergrid.persistence.Entity o ) {
-        if ( o == null ) {
-            return 1;
-        }
-        try {
-            long t1 = getUuid().timestamp();
-            long t2 = o.getUuid().timestamp();
-            return ( t1 < t2 ) ? -1 : ( t1 == t2 ) ? 0 : 1;
-        }
-        catch ( UnsupportedOperationException e ) {
-        }
-        return getUuid().compareTo( o.getUuid() );
+
+    @Override
+    public boolean isEmpty() {
+        return getDynamicProperties().isEmpty();
     }
 
 
-    public org.apache.usergrid.persistence.Entity toTypedEntity() {
-        org.apache.usergrid.persistence.Entity entity = EntityFactory.newEntity( getUuid(),
getType() );
-        entity.setProperties( getProperties() );
-        return entity;
+    @Override
+    public boolean containsKey( final Object key ) {
+        return getDynamicProperties().containsKey( key );
     }
 
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
+    @Override
+    public boolean containsValue( final Object value ) {
+        return getDynamicProperties().containsValue( value );
+    }
 
 
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ( ( uuid == null ) ? 0 : uuid.hashCode() );
-        return result;
+    @Override
+    public Object get( final Object key ) {
+        //All values are strings , so doing the cast here saves doing the cast elsewhere
+        return getDynamicProperties().get( key );
     }
 
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
+    @Override
+    public Object put( final String key, final Object value ) {
+        return getDynamicProperties().put( key,value );
+    }
+
+
+    @Override
+    public Object remove( final Object key ) {
+        return getDynamicProperties().remove( key );
+    }
+
+
+    @Override
+    public void putAll( final Map<? extends String, ?> m ) {
+        getDynamicProperties().putAll( m );
+    }
+
 
-    //    public boolean equals( Object obj ) {
-    //        if ( this == obj ) {
-    //            return true;
-    //        }
-    //        if ( obj == null ) {
-    //            return false;
-    //        }
-    //        if ( getClass() != obj.getClass() ) {
-    //            return false;
-    //        }
-    //        AbstractEntity other = ( AbstractEntity ) obj;
-    //        if ( uuid == null ) {
-    //            if ( other.uuid != null ) {
-    //                return false;
-    //            }
-    //        }
-    //        else if ( !uuid.equals( other.uuid ) ) {
-    //            return false;
-    //        }
-    //        return true;
-    //    }
+    @Override
+    public void clear() {
+        getDynamicProperties().clear();
+    }
+
+
+    @Override
+    public Set<String> keySet() {
+        return getDynamicProperties().keySet();
+    }
+
+
+    @Override
+    public java.util.Collection<Object> values() {
+        return getDynamicProperties().values();
+    }
+
+
+    @Override
+    public Set<Entry<String, Object>> entrySet() {
+        return getDynamicProperties().entrySet();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8bf8dccc/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
index 2853db1..bb2c71b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Organization.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.test.resource2point0.model;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.UUID;
 
 import org.apache.usergrid.utils.MapUtils;
@@ -34,12 +35,12 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 public class Organization extends Entity {
 
 
-    private String organization;
-    private String username;
-    private String email;
-    private String name;
-    private String password;
-    private String passwordHistorySize;
+//    private String organization;
+//    private String username;
+//    private String email;
+//    private String name;
+//    private String password;
+//    private String passwordHistorySize;
 
 
     public Organization() {
@@ -48,82 +49,40 @@ public class Organization extends Entity {
 
     public Organization( String orgName, String username, String email, String ownerName,
String password ){
 
-        this.dynamic_properties.put( "orgName",orgName );
+        this.put( "organization", orgName );
+        this.put( "username", username);
+        this.put( "email", email);
+        //TODO: create clearer distinction between ownerName and username in the backend.
+        this.put( "name", ownerName);
+        this.put( "password", password);
     }
 
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getOrganization( ) {
-        return ( String ) this.dynamic_properties.get( "orgName" );
-    }
-    public void setOrganization( final String orgName ) {
-        this.organization = orgName;
+        return ( String ) this.get( "organization" );
     }
 
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getUsername() {
-        return ( String ) this.dynamic_properties.get( "orgName" );
-    }
-
-
-    public void setUsername( final String username ) {
-        this.username = username;
+        return ( String ) this.get( "username" );
     }
 
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getEmail() {
-        return ( String ) this.dynamic_properties.get( "orgName" );
-    }
-
-
-    public void setEmail( final String email ) {
-        this.email = email;
+        return ( String ) this.get( "email" );
     }
 
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getName() {
-        return ( String ) this.dynamic_properties.get( "orgName" );
-    }
-
-    public void setName( final String name ) {
-        this.name = name;
+        return ( String ) this.get( "name" );
     }
 
-
     @JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
     public String getPassword() {
-        return ( String ) this.dynamic_properties.get( "orgName" );
+        return ( String ) this.get( "password" );
     }
 
-
-
-
-//    public String getOrganizationName(){
-//        return (String) dynamic_properties.get( "orgName" );
-//    }
-
-
-    public void setPasswordHistorySize( final String passwordHistorySize ) {
-        this.passwordHistorySize = passwordHistorySize;
+    public Object getPasswordHistorySize() {
+        return  (Integer) this.get("passwordHistorySize");
     }
-
-    //private String orgName;
-    //Keep the raw api response in here, dole out
-   // private ApiResponse apiResponse;
-
-    //Organizations are always initialized by name, and the uuid will be set on creations
-//    public Organization( final String orgName) {
-//        this.orgName = orgName;
-//    }
-
-    //Add setter and getter methods for throwing in relevant objects.
-//
-//    public UUID getUuid() {
-//        return (UUID)this.get( "uuid" );
-//    }
-//
-//    public String getOrgName() {
-//        return (String) this.get( "name" );
-//        //return orgName;
-//    }
-
 }


Mime
View raw message