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

Commit

Permalink
[USERGRID-396] Everywhere that an alias is used, we now do the repair…
Browse files Browse the repository at this point in the history
… entity retrieval.
  • Loading branch information
GERey committed Mar 12, 2015
1 parent a6929ab commit 4c0102e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
Expand Up @@ -148,7 +148,7 @@ public ServiceResults getItemByName( ServiceContext context, String name ) throw
nameProperty = "name";
}

EntityRef entity = em.getAlias( getEntityType(), name );
Entity entity = em.getAllEntityFromFields( getEntityType(), name );

if ( entity == null ) {
logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );
Expand All @@ -165,8 +165,7 @@ public ServiceResults getItemByName( ServiceContext context, String name ) throw
}

if ( !context.moreParameters() ) {
entity = em.get( entity );
entity = importEntity( context, ( Entity ) entity );
entity = importEntity( context, entity );
}

checkPermissionsForEntity( context, entity );
Expand Down Expand Up @@ -291,9 +290,9 @@ public ServiceResults putItemByName( ServiceContext context, String name ) throw
return getItemByName( context, name );
}

EntityRef ref = em.getAlias( getEntityType(), name );
Entity entity;
if ( ref == null ) {
// EntityRef ref = em.getAlias( getEntityType(), name );
Entity entity = em.getAllEntityFromFields( getEntityType(), name );
if ( entity == null ) {
// null entity ref means we tried to put a non-existing entity
// before we create a new entity for it, we should check for permission
checkPermissionsForCollection(context);
Expand All @@ -305,7 +304,6 @@ public ServiceResults putItemByName( ServiceContext context, String name ) throw
entity = em.create( getEntityType(), properties );
}
else {
entity = em.get( ref );
entity = importEntity( context, entity );
checkPermissionsForEntity( context, entity );
updateEntity( context, entity );
Expand Down Expand Up @@ -437,12 +435,12 @@ public ServiceResults postItemByName( ServiceContext context, String name ) thro
return super.postItemByName( context, name );
}

EntityRef ref = em.getAlias( getEntityType(), name );
if ( ref == null ) {
Entity entity = em.getAllEntityFromFields( getEntityType(), name );
if ( entity == null ) {
throw new ServiceResourceNotFoundException( context );
}

return postItemById( context, ref.getUuid() );
return postItemById( context, entity.getUuid() );
}


Expand Down Expand Up @@ -491,11 +489,7 @@ public ServiceResults deleteItemByName( ServiceContext context, String name ) th
return getItemByName( context, name );
}

EntityRef ref = em.getAlias( getEntityType(), name );
if ( ref == null ) {
throw new ServiceResourceNotFoundException( context );
}
Entity entity = em.get( ref );
Entity entity = em.getAllEntityFromFields(getEntityType(), name );
if ( entity == null ) {
throw new ServiceResourceNotFoundException( context );
}
Expand Down
Expand Up @@ -172,13 +172,13 @@ public ServiceResults getCollection( ServiceContext context ) throws Exception {
Results r = null;

if ( connecting() ) {
r = em.getConnectingEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
r = em.getConnectingEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
context.getCollectionName(), null, Level.ALL_PROPERTIES );
}
else {
r = em.getConnectedEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
r = em.getConnectedEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
context.getCollectionName(), null, Level.ALL_PROPERTIES );
}

Expand Down Expand Up @@ -239,7 +239,7 @@ public ServiceResults getItemByName( ServiceContext context, String name ) throw
throw new ServiceResourceNotFoundException( context );
}

if ( results.size() == 1 && !em.isConnectionMember(
if ( results.size() == 1 && !em.isConnectionMember(
context.getOwner(), context.getCollectionName(), results.getEntity() ) ) {
throw new ServiceResourceNotFoundException( context );
}
Expand All @@ -263,14 +263,9 @@ public ServiceResults getItemsByQuery( ServiceContext context, Query query ) thr
nameProperty = "name";
}

EntityRef ref = em.getAlias( query.getEntityType(), name );
if ( ref == null ) {
return null;
}

//TODO T.N. USERGRID-1919 actually validate this is connected

Entity entity = em.get( ref );
Entity entity = em.getAllEntityFromFields( query.getEntityType(),name );
if ( entity == null ) {
return null;
}
Expand All @@ -294,7 +289,7 @@ public ServiceResults getItemsByQuery( ServiceContext context, Query query ) thr
}

// query.setLimit( count );
// usergrid-2389: User defined limit in the query is ignored. Fixed it by following
// usergrid-2389: User defined limit in the query is ignored. Fixed it by following
// same style in AstractCollectionService
query.setLimit( query.getLimit( count ) );
query.setResultsLevel( level );
Expand All @@ -309,11 +304,11 @@ public ServiceResults getItemsByQuery( ServiceContext context, Query query ) thr
else {
// r = em.getConnectingEntities( context.getOwner().getUuid(), query.getConnectionType(),
// query.getEntityType(), level );
// usergrid-2389: User defined limit in the query is ignored. Fixed it by adding
// usergrid-2389: User defined limit in the query is ignored. Fixed it by adding
// the limit to the method parameter downstream.
r = em.getConnectingEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
query.getConnectionType(),query.getEntityType(), level , query.getLimit());
r = em.getConnectingEntities(
new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
query.getConnectionType(),query.getEntityType(), level , query.getLimit());
}
}
else {
Expand Down Expand Up @@ -366,11 +361,7 @@ public ServiceResults postItemsByQuery( ServiceContext context, Query query ) th
if ( query.containsSingleNameOrEmailIdentifier() ) {
String name = query.getSingleNameOrEmailIdentifier();

EntityRef ref = em.getAlias( query.getEntityType(), name );
if ( ref == null ) {
throw new ServiceResourceNotFoundException( context );
}
entity = em.get( ref );
entity = em.getAllEntityFromFields( query.getEntityType(), name );
if ( entity == null ) {
throw new ServiceResourceNotFoundException( context );
}
Expand Down Expand Up @@ -481,11 +472,7 @@ public ServiceResults deleteItemsByQuery( ServiceContext context, Query query )
nameProperty = "name";
}

EntityRef ref = em.getAlias( query.getEntityType(), name );
if ( ref == null ) {
throw new ServiceResourceNotFoundException( context );
}
Entity entity = em.get( ref );
Entity entity = em.getAllEntityFromFields( query.getEntityType(), name );
if ( entity == null ) {
throw new ServiceResourceNotFoundException( context );
}
Expand Down

0 comments on commit 4c0102e

Please sign in to comment.