You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by ro...@apache.org on 2014/12/22 17:54:31 UTC
[25/50] incubator-usergrid git commit: change interface
change interface
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/4ffd2e13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/4ffd2e13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/4ffd2e13
Branch: refs/heads/two-dot-o
Commit: 4ffd2e1326e17340d6408ef1f8c6ac8825fa1a05
Parents: 9084e36
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Dec 16 17:38:18 2014 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Dec 16 17:38:18 2014 -0700
----------------------------------------------------------------------
.../endpoints/AbstractCollectionResource.java | 6 ++++--
.../endpoints/AbstractEntityResource.java | 20 +++++++++++++-------
.../rest/test/resource2point0/model/Entity.java | 13 +------------
.../rest/test/resource2point0/model/Group.java | 6 +-----
.../rest/test/resource2point0/model/Role.java | 2 +-
5 files changed, 20 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4ffd2e13/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractCollectionResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractCollectionResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractCollectionResource.java
index 101e676..083a1f0 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractCollectionResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractCollectionResource.java
@@ -31,7 +31,7 @@ import javax.ws.rs.core.MediaType;
/**
* Classy class class.
*/
-public abstract class AbstractCollectionResource<T,Subresource> extends NamedResource {
+public abstract class AbstractCollectionResource<T extends Entity,Subresource> extends NamedResource {
public AbstractCollectionResource(String name, ClientContext context, UrlResource parent) {
super(name, context, parent);
}
@@ -47,6 +47,7 @@ public abstract class AbstractCollectionResource<T,Subresource> extends NamedRes
public ApiResponse get( final QueryParameters parameters){
return get(parameters,true);
}
+
/**
* Get a list of entities
* @return
@@ -64,8 +65,9 @@ public abstract class AbstractCollectionResource<T,Subresource> extends NamedRes
* @return
*/
public T post(final T entity){
- return instantiateT(getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
+ T obj = instantiateT(getResource(true).type( MediaType.APPLICATION_JSON_TYPE ).accept(MediaType.APPLICATION_JSON)
.post(ApiResponse.class, entity));
+ return obj;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4ffd2e13/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractEntityResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractEntityResource.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractEntityResource.java
index 28f20a9..1834e9f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractEntityResource.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/endpoints/AbstractEntityResource.java
@@ -22,6 +22,7 @@ package org.apache.usergrid.rest.test.resource2point0.endpoints;
import com.sun.jersey.api.client.WebResource;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
+import org.apache.usergrid.rest.test.resource2point0.model.Entity;
import org.apache.usergrid.rest.test.resource2point0.state.ClientContext;
import javax.ws.rs.core.MediaType;
@@ -29,7 +30,7 @@ import javax.ws.rs.core.MediaType;
/**
* Classy class class.
*/
-public abstract class AbstractEntityResource<T> extends NamedResource {
+public abstract class AbstractEntityResource<T extends Entity> extends NamedResource {
public AbstractEntityResource(String identifier, ClientContext context, UrlResource parent) {
super(identifier, context, parent);
@@ -42,17 +43,22 @@ public abstract class AbstractEntityResource<T> extends NamedResource {
return instantiateT(response);
}
- public ApiResponse post(final T entity) {
+ public T post(final T entity) {
WebResource resource = getResource(true);
- return resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
- .post(ApiResponse.class, entity);
+ return instantiateT(resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
+ .post(ApiResponse.class, entity));
}
- public ApiResponse put(final T entity) {
+ public T put(final T entity) {
WebResource resource = getResource(true);
- return resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
- .put(ApiResponse.class, entity);
+ return instantiateT(resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
+ .put(ApiResponse.class, entity));
}
+ public void delete(final T entity) {
+ WebResource resource = getResource(true);
+ resource.type(MediaType.APPLICATION_JSON_TYPE).accept(MediaType.APPLICATION_JSON)
+ .delete(ApiResponse.class, entity);
+ }
protected abstract T instantiateT(ApiResponse response);
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4ffd2e13/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 8d99eb4..bd50f2e 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
@@ -28,6 +28,7 @@ import java.util.*;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.rest.test.resource2point0.endpoints.AbstractCollectionResource;
import org.apache.usergrid.rest.test.resource2point0.endpoints.CollectionResource;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
@@ -49,7 +50,6 @@ public class Entity implements Serializable, Map<String,Object> {
protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
- private CollectionResource collectionResource;
public Entity(){}
@@ -61,14 +61,6 @@ public class Entity implements Serializable, Map<String,Object> {
}
}
- /**
- * Performs deep copy on entity passed in and save over what we currently have
- */
- public void save(){
- collectionResource.put(this);
- Entity entity = collectionResource.getSubresource(this.getName()).get();
- this.dynamic_properties.putAll(entity.getDynamicProperties());
- }
@JsonSerialize( include = JsonSerialize.Inclusion.NON_NULL )
@@ -252,9 +244,6 @@ public class Entity implements Serializable, Map<String,Object> {
return "Entity(" + getProperties() + ")";
}
- public CollectionResource getCollectionResource(){return collectionResource;}
- public void setCollectionResource(CollectionResource collectionResource){this.collectionResource = collectionResource;}
-
@JsonAnySetter
public void setDynamicProperty( String key, Object value ) {
if ( value == null || value.equals( "" ) ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4ffd2e13/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Group.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Group.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Group.java
index dc26cf1..865a278 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Group.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Group.java
@@ -33,11 +33,7 @@ public class Group extends Entity{
}
public Group (ApiResponse<Entity> response){
- if(response.getEntities() !=null && response.getEntities().size()>=1){
- List<Entity> entities = response.getEntities();
- Map<String,Object> entity = entities.get(0);
- this.putAll(entity);
- }
+ super(response);
}
public String getName(){
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4ffd2e13/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Role.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Role.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Role.java
index 7fa4d43..2d0a016 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Role.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/model/Role.java
@@ -30,7 +30,7 @@ public class Role extends Entity{
}
public Role (ApiResponse response){
- setResponse( response,"owner" );
+ super(response);
}
public String getName(){