Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Adds meta support on GET. The delete is not working correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd Nine committed Jun 2, 2015
1 parent 45ce5d2 commit b269520
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 17 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -81,6 +82,10 @@
import org.apache.usergrid.persistence.exceptions.UnexpectedEntityTypeException;
import org.apache.usergrid.persistence.graph.GraphManager;
import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.graph.SearchByEdgeType;
import org.apache.usergrid.persistence.graph.SearchEdgeType;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
import org.apache.usergrid.persistence.index.query.CounterResolution;
import org.apache.usergrid.persistence.index.query.Identifier;
import org.apache.usergrid.persistence.map.MapManager;
Expand Down Expand Up @@ -123,6 +128,8 @@
import static org.apache.commons.lang.StringUtils.capitalize;
import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.usergrid.corepersistence.util.CpEntityMapUtils.entityToCpEntity;
import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createConnectionTypeSearch;
import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getConnectionNameFromEdgeName;
import static org.apache.usergrid.persistence.Schema.COLLECTION_ROLES;
import static org.apache.usergrid.persistence.Schema.COLLECTION_USERS;
import static org.apache.usergrid.persistence.Schema.DICTIONARY_PERMISSIONS;
Expand Down Expand Up @@ -862,6 +869,9 @@ public Entity getUniqueEntityFromAlias( String collectionType, String aliasType
return convertMvccEntityToEntity( fieldSet.getEntity( uniqueLookupRepairField ).getEntity().get() );
}




@Override
public EntityRef getAlias( String aliasType, String alias ) throws Exception {

Expand Down Expand Up @@ -2853,7 +2863,7 @@ public UUID getApplicationId() {
@Override
public IndexBucketLocator getIndexBucketLocator() {

throw new UnsupportedOperationException( "Not supported yet." );
throw new UnsupportedOperationException( "Not supported ever." );
}


Expand All @@ -2869,6 +2879,32 @@ public void flushManagerCaches() {
}


@Override
public Set<String> getConnectionsAsSource( final EntityRef entityRef ) {

Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );

final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );

final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );

return graphManager.getEdgeTypesFromSource( searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) ).collect(
() -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last();
}


@Override
public Set<String> getConnectionsAsTarget( final EntityRef entityRef ) {
Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );

final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );

final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );

return graphManager.getEdgeTypesToTarget( searchByEdgeType ).map(
edgeName -> getConnectionNameFromEdgeName( edgeName ) ).collect( () -> new HashSet<String>( ), ( r, s ) -> r.add(s) ).toBlocking().last();
}




Expand Down
Expand Up @@ -34,8 +34,6 @@
import com.google.common.base.Optional;

import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getNameFromEdgeType;
Expand Down Expand Up @@ -98,7 +96,7 @@ private void doWalkCollections(
final String edgeType;
if ( collectionName == null ) {
// only search edge types that end with collections suffix
edgeType = CpNamingUtils.EDGE_COLL_SUFFIX;
edgeType = CpNamingUtils.EDGE_COLL_PREFIX;

} else {
// only search edges to one collection
Expand Down
Expand Up @@ -29,8 +29,10 @@
import org.apache.usergrid.persistence.graph.Edge;
import org.apache.usergrid.persistence.graph.SearchByEdge;
import org.apache.usergrid.persistence.graph.SearchByEdgeType;
import org.apache.usergrid.persistence.graph.SearchEdgeType;
import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
import org.apache.usergrid.persistence.index.IndexEdge;
import org.apache.usergrid.persistence.index.SearchEdge;
import org.apache.usergrid.persistence.index.impl.IndexEdgeImpl;
Expand All @@ -48,10 +50,20 @@
public class CpNamingUtils {

/** Edge types for collection suffix */
public static final String EDGE_COLL_SUFFIX = "zzzcollzzz";
public static final String EDGE_COLL_PREFIX = "zzzcollzzz";

/**
* The length used when we trim a string
*/
private static final int EDGE_COLL_PREFIX_LENGTH = EDGE_COLL_PREFIX.length() + 1;

/** Edge types for connection suffix */
public static final String EDGE_CONN_SUFFIX = "zzzconnzzz";
public static final String EDGE_CONN_PREFIX = "zzzconnzzz";

/**
* The length used when we trim a string on edge names
*/
private static final int EDGE_CONN_PREFIX_LENGTH = EDGE_CONN_PREFIX.length()+1;

/** App where we store management info */
public static final UUID MANAGEMENT_APPLICATION_ID = UUID.fromString( "b6768a08-b5d5-11e3-a495-11ddb1de66c8" );
Expand Down Expand Up @@ -81,19 +93,38 @@ public class CpNamingUtils {
* @param connectionType The type of connection made
*/
public static String getEdgeTypeFromConnectionType( String connectionType ) {
return ( EDGE_CONN_SUFFIX + "|" + connectionType ).toLowerCase();
return ( EDGE_CONN_PREFIX + "|" + connectionType ).toLowerCase();
}


/**
* Get the name of the collection from the edge name
* @param edgeName
* @return
*/
public static String getConnectionNameFromEdgeName(final String edgeName){
return edgeName.substring( EDGE_CONN_PREFIX_LENGTH );
}

/**
* Generate a standard edges from for a collection
*
* To be used only for searching DO NOT use for creation. Use the createCollectionEdge instead.
*/
public static String getEdgeTypeFromCollectionName( String collectionName ) {
return ( EDGE_COLL_SUFFIX + "|" + collectionName ).toLowerCase();
return ( EDGE_COLL_PREFIX + "|" + collectionName ).toLowerCase();
}

/**
* Get the name of the collection from the edge name
* @param edgeName
* @return
*/
public static String getCollectionNameFromEdgeName(final String edgeName){
return edgeName.substring( EDGE_COLL_PREFIX_LENGTH );
}



/**
* Get the index scope for the edge from the source to the target. The entity being indexed
Expand Down Expand Up @@ -210,6 +241,17 @@ public static SearchByEdge createConnectionSearchByEdge( final Id sourceId, fina
}



/**
* Create a search edge based on the type
*
* @param sourceId The id in the search
*/
public static SearchEdgeType createConnectionTypeSearch( final Id sourceId ) {
return new SimpleSearchEdgeType( sourceId, EDGE_CONN_PREFIX, null );
}


/**
* Get the application scope from the given uuid
*
Expand Down Expand Up @@ -263,7 +305,7 @@ public static String getNameFromEdgeType( final String edgeName ) {


private static boolean isCollectionEdgeType( String type ) {
return type.startsWith( EDGE_COLL_SUFFIX );
return type.startsWith( EDGE_COLL_PREFIX );
}


Expand Down
Expand Up @@ -28,6 +28,8 @@
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.usergrid.persistence.annotations.EntityProperty;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
Expand Down Expand Up @@ -88,6 +90,14 @@ public void setType( String type ) {
}



@Override
public Id asId() {
return new SimpleId( uuid, getType() );
}



@Override
@EntityProperty(indexed = true, required = true, mutable = false)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
Expand All @@ -105,6 +115,7 @@ public void setCreated( Long created ) {
}



@Override
@EntityProperty(indexed = true, required = true, mutable = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
Expand Down
Expand Up @@ -247,6 +247,8 @@ public void updateProperties( EntityRef entityRef, Map<String, Object> propertie
public Set<Object> getDictionaryAsSet( EntityRef entityRef, String dictionaryName )
throws Exception;



/**
* Adds the specified value to the named entity list property. Lists are a special type of
* entity property that can contain an unordered set of non-duplicate values.
Expand Down Expand Up @@ -332,6 +334,7 @@ public boolean isConnectionMember( EntityRef owner, String connectionName, Entit
throws Exception;



/**
* Gets the collections for the specified entity. Collection for a given type are encoded
* in the schema, this method loads the entity type and returns the collections from the schema.
Expand Down Expand Up @@ -697,4 +700,20 @@ Mutator<ByteBuffer> batchUpdateProperties(Mutator<ByteBuffer> batch,


public Entity getUniqueEntityFromAlias( String aliasType, String aliasValue );


/**
* Get the outgoing edge types where the entity ref is the source in the graph
* @param entityRef
* @return
*/
Set<String> getConnectionsAsSource(final EntityRef entityRef);


/**
* Get the outgoing edge types where the entity ref is the target node in the graph
* @param entityRef
* @return
*/
Set<String> getConnectionsAsTarget(final EntityRef entityRef);
}
Expand Up @@ -18,6 +18,9 @@

import java.util.UUID;

import org.apache.usergrid.persistence.model.entity.Id;


public interface EntityRef {

/**
Expand All @@ -33,4 +36,6 @@ public interface EntityRef {
* @return the type
*/
public String getType();

public Id asId();
}
Expand Up @@ -20,6 +20,9 @@
import java.util.Iterator;
import java.util.UUID;

import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;


/**
* For each in a set of source refs executes a sub-query and provides a unified iterator over
Expand Down Expand Up @@ -123,6 +126,13 @@ public String getType() {
return type;
}


@Override
public Id asId() {
return new SimpleId(uuid, type);
}


public void setType( String type ) {
this.type = type;
}
Expand Down
Expand Up @@ -20,6 +20,8 @@
import java.util.UUID;

import org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;


public class SimpleCollectionRef implements CollectionRef {
Expand Down Expand Up @@ -72,6 +74,12 @@ public String getType() {
}


@Override
public Id asId() {
return new SimpleId( id, type );
}


@Override
public String toString() {
if ( ( type == null ) && ( id == null ) ) {
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.UUID;

import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;


public class SimpleEntityRef implements EntityRef {
Expand Down Expand Up @@ -74,6 +75,12 @@ public String getType() {
}


@Override
public Id asId() {
return new SimpleId( uuid, type );
}


public static EntityRef ref( String entityType, UUID entityId ) {
return new SimpleEntityRef( entityType, entityId );
}
Expand Down
Expand Up @@ -22,6 +22,8 @@
import org.springframework.util.Assert;
import org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils;
import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.utils.StringUtils;
import org.apache.usergrid.utils.UUIDUtils;

Expand Down Expand Up @@ -98,6 +100,12 @@ public String getType() {
}


@Override
public Id asId() {
return new SimpleId( id, "role" );
}


@Override
public EntityRef getGroupRef() {
return new SimpleEntityRef( Group.ENTITY_TYPE, groupId );
Expand Down
Expand Up @@ -31,6 +31,8 @@
import org.apache.usergrid.persistence.ConnectionRef;
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.SimpleEntityRef;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -343,6 +345,12 @@ public String getType() {
}


@Override
public Id asId() {
return new SimpleId(id, CONNECTION_ENTITY_TYPE );
}


public UUID getIndexId() {
return getIndexId( getSourceRefs(), getConnectionType(), getConnectedEntityType(),
pairedConnections.toArray(new ConnectedEntityRef[pairedConnections.size()]));
Expand Down

0 comments on commit b269520

Please sign in to comment.