usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [02/36] usergrid git commit: Added a method to properly set the owner ( at least the email ) to the schema map in elastic search Removed traces of creating a new column family. Map manager is the way to go. Added the get endpoint to the service resource
Date Fri, 08 Apr 2016 20:20:49 GMT
Added a method to properly set the owner ( at least the email ) to the schema map in elastic
search
Removed traces of creating a new column family. Map manager is the way to go.
Added the get endpoint to the service resource that will allow us to do gets.
Added a way for the endpoint to read the JSON response and did the specific call out so that
we could work around having to make a service ( Which is bad code )

Returned an object with a terrible name to debug the response that gets returned.
Added AbstractCollectionService method that allows us to get the workaround to a normal call
in order to get around path permission checking.
AbstractService has the workaround which is what needs to be done if you want to avoid using
a schema.
Added a new service action for the work around.


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

Branch: refs/heads/release-2.1.1
Commit: 58e6cf38660350b16f3d443dfe781bc9f1c90903
Parents: 56e0371
Author: George Reyes <grey@apache.org>
Authored: Mon Mar 7 10:40:27 2016 -0800
Committer: George Reyes <grey@apache.org>
Committed: Thu Mar 24 09:05:42 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 49 +++++++++-
 .../usergrid/persistence/EntityManager.java     |  4 +
 .../persistence/cassandra/ApplicationCF.java    |  5 -
 .../rest/applications/ServiceResource.java      | 98 +++++++++++++++++++-
 .../collection/CollectionsResourceIT.java       |  2 +-
 .../services/AbstractCollectionService.java     | 19 ++++
 .../services/AbstractConnectionsService.java    |  7 ++
 .../usergrid/services/AbstractService.java      |  7 ++
 .../apache/usergrid/services/ServiceAction.java |  2 +-
 .../applications/ApplicationsService.java       |  7 ++
 10 files changed, 190 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 3dbdb7d..6a6d036 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -17,11 +17,15 @@ package org.apache.usergrid.corepersistence;
 
 
 import java.nio.ByteBuffer;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -1730,8 +1734,49 @@ public class CpEntityManager implements EntityManager {
         return get( id, Role.class );
     }
 
+    @Override
+    public Map createCollectionSchema( String collectionName, String owner ,Map<String,
Object> properties ){
+
+
+        //haven't decided which one I should base off of which, maybe from epoch to utc
+        Instant timeInstance = Instant.now();
+
+        Date date = Date.from(timeInstance);
+        Long epoch = timeInstance.toEpochMilli();
+
+        Map<String,Object> schemaMap = new HashMap<>(  );
+
+
+        schemaMap.put("lastUpdated",epoch);
+        //this needs the method that can extract the user from the token no matter the token.
+        //Possible values are app credentials, org credentials, or the user email(Admin tokens).
+        schemaMap.put("lastUpdateBy",owner);
+        schemaMap.put("lastReindexed",0);
+        schemaMap.putAll( properties );
+
+        //Map<String,Object> fields = properties.get( "properties" );
+
+        //for(Object)
+
+        MapManager mm = getMapManagerForTypes();
+        mm.putString( collectionName,schemaMap.toString() );
+
+        return schemaMap;
+
+    }
 
     @Override
+    public Entity createCollectionSchema( String collectionName ){
+        MapManager mm = getMapManagerForTypes();
+        String jsonMap = mm.getString( collectionName );
+
+        Object obj = JsonUtils.parse( jsonMap );
+
+        return null;
+    }
+
+
+        @Override
     public void grantRolePermission( String roleName, String permission ) throws Exception
{
         roleName = roleName.toLowerCase();
         permission = permission.toLowerCase();
@@ -2663,6 +2708,7 @@ public class CpEntityManager implements EntityManager {
                     cpEntity.getId().getType(), cpEntity.getId().getUuid(), cpEntity.getVersion()
);
             }
 
+            //this does the write so before adding to a collection everything already exists
already.
             cpEntity = ecm.write( cpEntity ).toBlocking().last();
             entity.setSize(cpEntity.getSize());
 
@@ -2683,6 +2729,8 @@ public class CpEntityManager implements EntityManager {
         // add to and index in collection of the application
         if ( !is_application ) {
 
+            //maybe a check here to see if it exists in the column family and if it doesn't
then SEND IT ON THROUGHH
+
             String collectionName = Schema.defaultCollectionName( eType );
             CpRelationManager cpr = ( CpRelationManager ) getRelationManager( getApplication()
);
             cpr.addToCollection( collectionName, entity );
@@ -2695,7 +2743,6 @@ public class CpEntityManager implements EntityManager {
         MapManager mm = getMapManagerForTypes();
         mm.putString( itemId.toString(), entity.getType() );
 
-
         return entity;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 1a844f6..7c5cc5b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -512,6 +512,10 @@ public interface EntityManager {
      */
     public Entity createRole( String roleName, String roleTitle, long inactivity ) throws
Exception;
 
+    public Map createCollectionSchema( String collectionName, String owner ,Map<String,
Object> properties );
+
+    Entity createCollectionSchema( String collectionName );
+
     public void grantRolePermission( String roleName, String permission ) throws Exception;
 
     public void grantRolePermissions( String roleName, Collection<String> permissions
) throws Exception;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
index ad72717..242d360 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/ApplicationCF.java
@@ -46,11 +46,6 @@ public enum ApplicationCF implements CFEnum {
     /** Entity counters */
     ENTITY_COUNTERS( "Entity_Counters", "BytesType", COUNTERTYPE.getClassName() );
 
-    /**
-     * Collection Schema
-     */
-    COL_SCHEMA( "")
-
     private final String cf;
     private final String comparator;
     private final String validator;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index 2843417..3318adf 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -244,6 +244,55 @@ public class ServiceResource extends AbstractContextResource {
         return getSubResource( ServiceResource.class );
     }
 
+    public ServiceResults executeServiceRequestForSchema(UriInfo ui, ApiResponse response,
ServiceAction action,
+                                                         ServicePayload payload) throws Exception
{
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.executeServiceRequest" );
+        }
+
+
+        boolean tree = "true".equalsIgnoreCase( ui.getQueryParameters().getFirst( "tree"
) );
+
+        String connectionQueryParm = ui.getQueryParameters().getFirst("connections");
+        boolean returnInboundConnections = true;
+        boolean returnOutboundConnections = true;
+
+        addQueryParams( getServiceParameters(), ui );
+
+        ServiceRequest r = services.newRequest( action, tree, getServiceParameters(), payload,
+            returnInboundConnections, returnOutboundConnections );
+
+        response.setServiceRequest( r );
+        ServiceResults results = r.execute();
+        if ( results != null ) {
+            if ( results.hasData() ) {
+                response.setData( results.getData() );
+            }
+            if ( results.getServiceMetadata() != null ) {
+                response.setMetadata( results.getServiceMetadata() );
+            }
+            Query query = r.getLastQuery();
+            if ( query != null ) {
+                if ( query.hasSelectSubjects() ) {
+                    response.setList( QueryUtils.getSelectionResults( query, results ) );
+                    response.setCount( response.getList().size() );
+                    response.setNext( results.getNextResult() );
+                    response.setPath( results.getPath() );
+                    return results;
+                }
+            }
+
+            response.setResults( results );
+        }
+
+        httpServletRequest.setAttribute( "applicationId", services.getApplicationId() );
+
+        return results;
+
+
+    }
+
 
     public ServiceResults executeServiceRequest( UriInfo ui, ApiResponse response, ServiceAction
action,
                                                  ServicePayload payload ) throws Exception
{
@@ -366,7 +415,7 @@ public class ServiceResource extends AbstractContextResource {
     @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
     @RequireApplicationAccess
     @JSONP
-    public ApiResponse executePostOnIndexes( @Context UriInfo ui,
+    public ApiResponse executePostOnIndexes( @Context UriInfo ui, String body,
                                    @QueryParam("callback") @DefaultValue("callback") String
callback )
         throws Exception {
 
@@ -374,17 +423,62 @@ public class ServiceResource extends AbstractContextResource {
             logger.trace( "ServiceResource.executePostOnIndexes" );
         }
 
+        Object json;
+        if ( StringUtils.isEmpty( body ) ) {
+            json = null;
+        } else {
+            json = readJsonToObject( body );
+        }
+
         ApiResponse response = createApiResponse();
 
         response.setAction( "post" );
         response.setApplication( services.getApplication() );
         response.setParams( ui.getQueryParameters() );
 
-        executeServiceRequest( ui, response, ServiceAction.POST, null );
+        ServicePayload payload = getPayload( json );
+
+        executeServiceRequestForSchema( ui,response,ServiceAction.SCHEMA,payload );
+
+        return response;
+    }
+
+    @GET
+    @Path("_index")
+    @Produces({MediaType.APPLICATION_JSON,"application/javascript"})
+    @RequireApplicationAccess
+    @JSONP
+    public ApiResponse executeGetOnIndex( @Context UriInfo ui, String body,
+                                             @QueryParam("callback") @DefaultValue("callback")
String callback )
+        throws Exception {
+
+        if(logger.isTraceEnabled()){
+            logger.trace( "ServiceResource.executePostOnIndexes" );
+        }
+
+        Object json;
+        if ( StringUtils.isEmpty( body ) ) {
+            json = null;
+        } else {
+            json = readJsonToObject( body );
+        }
+
+        ApiResponse response = createApiResponse();
+
+
+
+        response.setAction( "get" );
+        response.setApplication( services.getApplication() );
+        response.setParams( ui.getQueryParameters() );
+
+        ServicePayload payload = getPayload( json );
+
+        executeServiceRequest( ui, response, ServiceAction.GET, payload );
 
         return response;
     }
 
+
     @SuppressWarnings({ "unchecked" })
     public ServicePayload getPayload( Object json ) {
         ServicePayload payload = null;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index ca5360d..773317b 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -149,7 +149,7 @@ public class CollectionsResourceIT extends AbstractRestIT {
         payload.put( "fields", indexingArray);
 
         //Post index to the collection metadata
-        this.app().collection( "testCollection" ).collection( "_indexes" ).post( payload
);
+        Object thing = this.app().collection( "testCollection" ).collection( "_indexes" ).post(
payload );
         refreshIndex();
 
         //Below is what needs to be implemented along with the index call above

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index 0ad751a..f6d2849 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -25,6 +25,9 @@ import java.util.UUID;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+
+import org.apache.shiro.subject.Subject;
+
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.Query;
@@ -34,6 +37,8 @@ import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
 import org.apache.usergrid.persistence.exceptions.UnexpectedEntityTypeException;
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.security.shiro.principals.AdminUserPrincipal;
+import org.apache.usergrid.security.shiro.utils.SubjectUtils;
 import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.ForbiddenServiceOperationException;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
@@ -318,6 +323,20 @@ public class AbstractCollectionService extends AbstractService {
         return new ServiceResults( this, context, Type.COLLECTION, r, null, null );
     }
 
+    @Override
+    public ServiceResults postCollectionSchema( ServiceContext context ) throws Exception
{
+        context.setAction( ServiceAction.POST );
+        checkPermissionsForCollection( context );
+        Subject currentUser = SubjectUtils.getSubject();
+        Object currentUser2 =currentUser.getPrincipal();
+
+        Map collectionSchema = em.createCollectionSchema(context.getCollectionName(),
+            ( ( AdminUserPrincipal ) currentUser2 ).getUser().getEmail(),context.getProperties());
+
+        return new ServiceResults( this, context, Type.COLLECTION, Results.fromData( collectionSchema
), null, null );
+
+    }
+
 
     @Override
     public ServiceResults postCollection( ServiceContext context ) throws Exception {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
index 94b25d3..666f676 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
@@ -38,6 +38,7 @@ import org.apache.usergrid.services.ServiceParameter.NameParameter;
 import org.apache.usergrid.services.ServiceParameter.QueryParameter;
 import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
+import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
 
 import rx.Observable;
 import rx.schedulers.Schedulers;
@@ -391,6 +392,12 @@ public class AbstractConnectionsService extends AbstractService {
 
 
     @Override
+    public ServiceResults postCollectionSchema( final ServiceContext context ) throws Exception
{
+        throw new UnsupportedServiceOperationException( context );
+    }
+
+
+    @Override
     public ServiceResults putItemById( ServiceContext context, UUID id ) throws Exception
{
 
         if ( context.moreParameters() ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
index 5d818cc..3c5503c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractService.java
@@ -55,6 +55,7 @@ import org.apache.usergrid.services.ServiceResults.Type;
 import org.apache.usergrid.services.exceptions.ServiceInvocationException;
 import org.apache.usergrid.services.exceptions.ServiceResourceNotFoundException;
 import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
+import org.apache.usergrid.services.generic.RootCollectionService;
 
 import com.google.inject.Injector;
 import com.google.inject.Key;
@@ -827,6 +828,9 @@ public abstract class AbstractService implements Service {
 
             case HEAD:
                 return headCollection( context );
+
+            case SCHEMA:
+                return postCollectionSchema( context );
         }
 
         throw new ServiceInvocationException( context, "Request action unhandled " + context.getAction()
);
@@ -888,6 +892,9 @@ public abstract class AbstractService implements Service {
     }
 
 
+    public abstract ServiceResults postCollectionSchema( ServiceContext context ) throws
Exception;
+
+
     public ServiceResults postCollection( ServiceContext context ) throws Exception {
         throw new UnsupportedServiceOperationException( context );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/services/src/main/java/org/apache/usergrid/services/ServiceAction.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/ServiceAction.java
b/stack/services/src/main/java/org/apache/usergrid/services/ServiceAction.java
index e1c6133..ec34df4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/ServiceAction.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/ServiceAction.java
@@ -18,5 +18,5 @@ package org.apache.usergrid.services;
 
 
 public enum ServiceAction {
-    POST, GET, PUT, DELETE, HEAD, OPTIONS;
+    POST, GET, PUT, DELETE, HEAD, OPTIONS, SCHEMA;
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/58e6cf38/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
index ae524c6..cf4aa80 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/applications/ApplicationsService.java
@@ -34,6 +34,7 @@ import org.apache.usergrid.services.ServiceParameter.QueryParameter;
 import org.apache.usergrid.services.ServicePayload;
 import org.apache.usergrid.services.ServiceResults;
 import org.apache.usergrid.services.ServiceResults.Type;
+import org.apache.usergrid.services.exceptions.UnsupportedServiceOperationException;
 
 import org.apache.commons.lang.StringUtils;
 
@@ -94,6 +95,12 @@ public class ApplicationsService extends AbstractService {
 
 
     @Override
+    public ServiceResults postCollectionSchema( final ServiceContext context ) throws Exception
{
+        throw new UnsupportedServiceOperationException( context );
+    }
+
+
+    @Override
     public ServiceResults getEntityDictionary( ServiceContext context, List<EntityRef>
refs,
                                                EntityDictionaryEntry dictionary ) throws
Exception {
 


Mime
View raw message