@ -26,7 +26,9 @@ import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching ;
import org.springframework.stereotype.Service ;
import org.springframework.util.StringUtils ;
import org.thingsboard.server.common.data.Tenant ;
import org.thingsboard.server.common.data.id.EntityId ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.data.relation.EntityRelation ;
import org.thingsboard.server.common.data.relation.EntityRelationInfo ;
import org.thingsboard.server.common.data.relation.EntityRelationsQuery ;
@ -66,27 +68,27 @@ public class BaseRelationService implements RelationService {
private CacheManager cacheManager ;
@Override
public ListenableFuture < Boolean > checkRelation ( EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public ListenableFuture < Boolean > checkRelation ( TenantId tenantId , EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing checkRelation [{}][{}][{}][{}]" , from , to , relationType , typeGroup ) ;
validate ( from , to , relationType , typeGroup ) ;
return relationDao . checkRelation ( from , to , relationType , typeGroup ) ;
return relationDao . checkRelation ( tenantId , from , to , relationType , typeGroup ) ;
}
@Cacheable ( cacheNames = RELATIONS_CACHE , key = "{#from, #to, #relationType, #typeGroup}" )
@Override
public EntityRelation getRelation ( EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public EntityRelation getRelation ( TenantId tenantId , EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
try {
return getRelationAsync ( from , to , relationType , typeGroup ) . get ( ) ;
return getRelationAsync ( tenantId , from , to , relationType , typeGroup ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < EntityRelation > getRelationAsync ( EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public ListenableFuture < EntityRelation > getRelationAsync ( TenantId tenantId , EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing EntityRelation [{}][{}][{}][{}]" , from , to , relationType , typeGroup ) ;
validate ( from , to , relationType , typeGroup ) ;
return relationDao . getRelation ( from , to , relationType , typeGroup ) ;
return relationDao . getRelation ( tenantId , from , to , relationType , typeGroup ) ;
}
@Caching ( evict = {
@ -97,10 +99,10 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#relation.to, #relation.type, #relation.typeGroup, 'TO'}" )
} )
@Override
public boolean saveRelation ( EntityRelation relation ) {
public boolean saveRelation ( TenantId tenantId , EntityRelation relation ) {
log . trace ( "Executing saveRelation [{}]" , relation ) ;
validate ( relation ) ;
return relationDao . saveRelation ( relation ) ;
return relationDao . saveRelation ( tenantId , relation ) ;
}
@Caching ( evict = {
@ -111,10 +113,10 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#relation.to, #relation.type, #relation.typeGroup, 'TO'}" )
} )
@Override
public ListenableFuture < Boolean > saveRelationAsync ( EntityRelation relation ) {
public ListenableFuture < Boolean > saveRelationAsync ( TenantId tenantId , EntityRelation relation ) {
log . trace ( "Executing saveRelationAsync [{}]" , relation ) ;
validate ( relation ) ;
return relationDao . saveRelationAsync ( relation ) ;
return relationDao . saveRelationAsync ( tenantId , relation ) ;
}
@Caching ( evict = {
@ -125,10 +127,10 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#relation.to, #relation.type, #relation.typeGroup, 'TO'}" )
} )
@Override
public boolean deleteRelation ( EntityRelation relation ) {
public boolean deleteRelation ( TenantId tenantId , EntityRelation relation ) {
log . trace ( "Executing deleteRelation [{}]" , relation ) ;
validate ( relation ) ;
return relationDao . deleteRelation ( relation ) ;
return relationDao . deleteRelation ( tenantId , relation ) ;
}
@Caching ( evict = {
@ -139,10 +141,10 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#relation.to, #relation.type, #relation.typeGroup, 'TO'}" )
} )
@Override
public ListenableFuture < Boolean > deleteRelationAsync ( EntityRelation relation ) {
public ListenableFuture < Boolean > deleteRelationAsync ( TenantId tenantId , EntityRelation relation ) {
log . trace ( "Executing deleteRelationAsync [{}]" , relation ) ;
validate ( relation ) ;
return relationDao . deleteRelationAsync ( relation ) ;
return relationDao . deleteRelationAsync ( tenantId , relation ) ;
}
@Caching ( evict = {
@ -153,10 +155,10 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#to, #relationType, #typeGroup, 'TO'}" )
} )
@Override
public boolean deleteRelation ( EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public boolean deleteRelation ( TenantId tenantId , EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing deleteRelation [{}][{}][{}][{}]" , from , to , relationType , typeGroup ) ;
validate ( from , to , relationType , typeGroup ) ;
return relationDao . deleteRelation ( from , to , relationType , typeGroup ) ;
return relationDao . deleteRelation ( tenantId , from , to , relationType , typeGroup ) ;
}
@Caching ( evict = {
@ -167,69 +169,69 @@ public class BaseRelationService implements RelationService {
@CacheEvict ( cacheNames = RELATIONS_CACHE , key = "{#to, #relationType, #typeGroup, 'TO'}" )
} )
@Override
public ListenableFuture < Boolean > deleteRelationAsync ( EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public ListenableFuture < Boolean > deleteRelationAsync ( TenantId tenantId , EntityId from , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing deleteRelationAsync [{}][{}][{}][{}]" , from , to , relationType , typeGroup ) ;
validate ( from , to , relationType , typeGroup ) ;
return relationDao . deleteRelationAsync ( from , to , relationType , typeGroup ) ;
return relationDao . deleteRelationAsync ( tenantId , from , to , relationType , typeGroup ) ;
}
@Override
public void deleteEntityRelations ( EntityId entityId ) {
public void deleteEntityRelations ( TenantId tenantId , EntityId entityId ) {
try {
deleteEntityRelationsAsync ( entityId ) . get ( ) ;
deleteEntityRelationsAsync ( tenantId , entityId ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < Void > deleteEntityRelationsAsync ( EntityId entityId ) {
public ListenableFuture < Void > deleteEntityRelationsAsync ( TenantId tenantId , EntityId entityId ) {
Cache cache = cacheManager . getCache ( RELATIONS_CACHE ) ;
log . trace ( "Executing deleteEntityRelationsAsync [{}]" , entityId ) ;
validate ( entityId ) ;
List < ListenableFuture < List < EntityRelation > > > inboundRelationsList = new ArrayList < > ( ) ;
for ( RelationTypeGroup typeGroup : RelationTypeGroup . values ( ) ) {
inboundRelationsList . add ( relationDao . findAllByTo ( entityId , typeGroup ) ) ;
inboundRelationsList . add ( relationDao . findAllByTo ( tenantId , entityId , typeGroup ) ) ;
}
ListenableFuture < List < List < EntityRelation > > > inboundRelations = Futures . allAsList ( inboundRelationsList ) ;
List < ListenableFuture < List < EntityRelation > > > outboundRelationsList = new ArrayList < > ( ) ;
for ( RelationTypeGroup typeGroup : RelationTypeGroup . values ( ) ) {
outboundRelationsList . add ( relationDao . findAllByFrom ( entityId , typeGroup ) ) ;
outboundRelationsList . add ( relationDao . findAllByFrom ( tenantId , entityId , typeGroup ) ) ;
}
ListenableFuture < List < List < EntityRelation > > > outboundRelations = Futures . allAsList ( outboundRelationsList ) ;
ListenableFuture < List < Boolean > > inboundDeletions = Futures . transformAsync ( inboundRelations ,
relations - > {
List < ListenableFuture < Boolean > > results = deleteRelationGroupsAsync ( relations , cache , true ) ;
List < ListenableFuture < Boolean > > results = deleteRelationGroupsAsync ( tenantId , relations , cache , true ) ;
return Futures . allAsList ( results ) ;
} ) ;
ListenableFuture < List < Boolean > > outboundDeletions = Futures . transformAsync ( outboundRelations ,
relations - > {
List < ListenableFuture < Boolean > > results = deleteRelationGroupsAsync ( relations , cache , false ) ;
List < ListenableFuture < Boolean > > results = deleteRelationGroupsAsync ( tenantId , relations , cache , false ) ;
return Futures . allAsList ( results ) ;
} ) ;
ListenableFuture < List < List < Boolean > > > deletionsFuture = Futures . allAsList ( inboundDeletions , outboundDeletions ) ;
return Futures . transform ( Futures . transformAsync ( deletionsFuture , ( deletions ) - > relationDao . deleteOutboundRelationsAsync ( entityId ) ) , result - > null ) ;
return Futures . transform ( Futures . transformAsync ( deletionsFuture , ( deletions ) - > relationDao . deleteOutboundRelationsAsync ( tenantId , entityId ) ) , result - > null ) ;
}
private List < ListenableFuture < Boolean > > deleteRelationGroupsAsync ( List < List < EntityRelation > > relations , Cache cache , boolean deleteFromDb ) {
private List < ListenableFuture < Boolean > > deleteRelationGroupsAsync ( TenantId tenantId , List < List < EntityRelation > > relations , Cache cache , boolean deleteFromDb ) {
List < ListenableFuture < Boolean > > results = new ArrayList < > ( ) ;
for ( List < EntityRelation > relationList : relations ) {
relationList . forEach ( relation - > results . add ( deleteAsync ( cache , relation , deleteFromDb ) ) ) ;
relationList . forEach ( relation - > results . add ( deleteAsync ( tenantId , cache , relation , deleteFromDb ) ) ) ;
}
return results ;
}
private ListenableFuture < Boolean > deleteAsync ( Cache cache , EntityRelation relation , boolean deleteFromDb ) {
private ListenableFuture < Boolean > deleteAsync ( TenantId tenantId , Cache cache , EntityRelation relation , boolean deleteFromDb ) {
cacheEviction ( relation , cache ) ;
if ( deleteFromDb ) {
return relationDao . deleteRelationAsync ( relation ) ;
return relationDao . deleteRelationAsync ( tenantId , relation ) ;
} else {
return Futures . immediateFuture ( false ) ;
}
@ -272,18 +274,18 @@ public class BaseRelationService implements RelationService {
@Cacheable ( cacheNames = RELATIONS_CACHE , key = "{#from, #typeGroup, 'FROM'}" )
@Override
public List < EntityRelation > findByFrom ( EntityId from , RelationTypeGroup typeGroup ) {
public List < EntityRelation > findByFrom ( TenantId tenantId , EntityId from , RelationTypeGroup typeGroup ) {
validate ( from ) ;
validateTypeGroup ( typeGroup ) ;
try {
return relationDao . findAllByFrom ( from , typeGroup ) . get ( ) ;
return relationDao . findAllByFrom ( tenantId , from , typeGroup ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < List < EntityRelation > > findByFromAsync ( EntityId from , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelation > > findByFromAsync ( TenantId tenantId , EntityId from , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findByFrom [{}][{}]" , from , typeGroup ) ;
validate ( from ) ;
validateTypeGroup ( typeGroup ) ;
@ -298,7 +300,7 @@ public class BaseRelationService implements RelationService {
if ( fromCache ! = null ) {
return Futures . immediateFuture ( fromCache ) ;
} else {
ListenableFuture < List < EntityRelation > > relationsFuture = relationDao . findAllByFrom ( from , typeGroup ) ;
ListenableFuture < List < EntityRelation > > relationsFuture = relationDao . findAllByFrom ( tenantId , from , typeGroup ) ;
Futures . addCallback ( relationsFuture ,
new FutureCallback < List < EntityRelation > > ( ) {
@Override
@ -313,16 +315,16 @@ public class BaseRelationService implements RelationService {
}
@Override
public ListenableFuture < List < EntityRelationInfo > > findInfoByFrom ( EntityId from , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelationInfo > > findInfoByFrom ( TenantId tenantId , EntityId from , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findInfoByFrom [{}][{}]" , from , typeGroup ) ;
validate ( from ) ;
validateTypeGroup ( typeGroup ) ;
ListenableFuture < List < EntityRelation > > relations = relationDao . findAllByFrom ( from , typeGroup ) ;
ListenableFuture < List < EntityRelation > > relations = relationDao . findAllByFrom ( tenantId , from , typeGroup ) ;
return Futures . transformAsync ( relations ,
relations1 - > {
List < ListenableFuture < EntityRelationInfo > > futures = new ArrayList < > ( ) ;
relations1 . forEach ( relation - >
futures . add ( fetchRelationInfoAsync ( relation ,
futures . add ( fetchRelationInfoAsync ( tenantId , relation ,
EntityRelation : : getTo ,
EntityRelationInfo : : setToName ) )
) ;
@ -332,37 +334,37 @@ public class BaseRelationService implements RelationService {
@Cacheable ( cacheNames = RELATIONS_CACHE , key = "{#from, #relationType, #typeGroup, 'FROM'}" )
@Override
public List < EntityRelation > findByFromAndType ( EntityId from , String relationType , RelationTypeGroup typeGroup ) {
public List < EntityRelation > findByFromAndType ( TenantId tenantId , EntityId from , String relationType , RelationTypeGroup typeGroup ) {
try {
return findByFromAndTypeAsync ( from , relationType , typeGroup ) . get ( ) ;
return findByFromAndTypeAsync ( tenantId , from , relationType , typeGroup ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < List < EntityRelation > > findByFromAndTypeAsync ( EntityId from , String relationType , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelation > > findByFromAndTypeAsync ( TenantId tenantId , EntityId from , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findByFromAndType [{}][{}][{}]" , from , relationType , typeGroup ) ;
validate ( from ) ;
validateType ( relationType ) ;
validateTypeGroup ( typeGroup ) ;
return relationDao . findAllByFromAndType ( from , relationType , typeGroup ) ;
return relationDao . findAllByFromAndType ( tenantId , from , relationType , typeGroup ) ;
}
@Cacheable ( cacheNames = RELATIONS_CACHE , key = "{#to, #typeGroup, 'TO'}" )
@Override
public List < EntityRelation > findByTo ( EntityId to , RelationTypeGroup typeGroup ) {
public List < EntityRelation > findByTo ( TenantId tenantId , EntityId to , RelationTypeGroup typeGroup ) {
validate ( to ) ;
validateTypeGroup ( typeGroup ) ;
try {
return relationDao . findAllByTo ( to , typeGroup ) . get ( ) ;
return relationDao . findAllByTo ( tenantId , t o , typeGroup ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < List < EntityRelation > > findByToAsync ( EntityId to , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelation > > findByToAsync ( TenantId tenantId , EntityId to , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findByTo [{}][{}]" , to , typeGroup ) ;
validate ( to ) ;
validateTypeGroup ( typeGroup ) ;
@ -377,7 +379,7 @@ public class BaseRelationService implements RelationService {
if ( fromCache ! = null ) {
return Futures . immediateFuture ( fromCache ) ;
} else {
ListenableFuture < List < EntityRelation > > relationsFuture = relationDao . findAllByTo ( to , typeGroup ) ;
ListenableFuture < List < EntityRelation > > relationsFuture = relationDao . findAllByTo ( tenantId , t o , typeGroup ) ;
Futures . addCallback ( relationsFuture ,
new FutureCallback < List < EntityRelation > > ( ) {
@Override
@ -392,16 +394,16 @@ public class BaseRelationService implements RelationService {
}
@Override
public ListenableFuture < List < EntityRelationInfo > > findInfoByTo ( EntityId to , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelationInfo > > findInfoByTo ( TenantId tenantId , EntityId to , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findInfoByTo [{}][{}]" , to , typeGroup ) ;
validate ( to ) ;
validateTypeGroup ( typeGroup ) ;
ListenableFuture < List < EntityRelation > > relations = relationDao . findAllByTo ( to , typeGroup ) ;
ListenableFuture < List < EntityRelation > > relations = relationDao . findAllByTo ( tenantId , t o , typeGroup ) ;
return Futures . transformAsync ( relations ,
relations1 - > {
List < ListenableFuture < EntityRelationInfo > > futures = new ArrayList < > ( ) ;
relations1 . forEach ( relation - >
futures . add ( fetchRelationInfoAsync ( relation ,
futures . add ( fetchRelationInfoAsync ( tenantId , relation ,
EntityRelation : : getFrom ,
EntityRelationInfo : : setFromName ) )
) ;
@ -409,10 +411,10 @@ public class BaseRelationService implements RelationService {
} ) ;
}
private ListenableFuture < EntityRelationInfo > fetchRelationInfoAsync ( EntityRelation relation ,
private ListenableFuture < EntityRelationInfo > fetchRelationInfoAsync ( TenantId tenantId , EntityRelation relation ,
Function < EntityRelation , EntityId > entityIdGetter ,
BiConsumer < EntityRelationInfo , String > entityNameSetter ) {
ListenableFuture < String > entityName = entityService . fetchEntityNameAsync ( entityIdGetter . apply ( relation ) ) ;
ListenableFuture < String > entityName = entityService . fetchEntityNameAsync ( tenantId , entityIdGetter . apply ( relation ) ) ;
return Futures . transform ( entityName , entityName1 - > {
EntityRelationInfo entityRelationInfo1 = new EntityRelationInfo ( relation ) ;
entityNameSetter . accept ( entityRelationInfo1 , entityName1 ) ;
@ -422,25 +424,25 @@ public class BaseRelationService implements RelationService {
@Cacheable ( cacheNames = RELATIONS_CACHE , key = "{#to, #relationType, #typeGroup, 'TO'}" )
@Override
public List < EntityRelation > findByToAndType ( EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public List < EntityRelation > findByToAndType ( TenantId tenantId , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
try {
return findByToAndTypeAsync ( to , relationType , typeGroup ) . get ( ) ;
return findByToAndTypeAsync ( tenantId , t o , relationType , typeGroup ) . get ( ) ;
} catch ( InterruptedException | ExecutionException e ) {
throw new RuntimeException ( e ) ;
}
}
@Override
public ListenableFuture < List < EntityRelation > > findByToAndTypeAsync ( EntityId to , String relationType , RelationTypeGroup typeGroup ) {
public ListenableFuture < List < EntityRelation > > findByToAndTypeAsync ( TenantId tenantId , EntityId to , String relationType , RelationTypeGroup typeGroup ) {
log . trace ( "Executing findByToAndType [{}][{}][{}]" , to , relationType , typeGroup ) ;
validate ( to ) ;
validateType ( relationType ) ;
validateTypeGroup ( typeGroup ) ;
return relationDao . findAllByToAndType ( to , relationType , typeGroup ) ;
return relationDao . findAllByToAndType ( tenantId , t o , relationType , typeGroup ) ;
}
@Override
public ListenableFuture < List < EntityRelation > > findByQuery ( EntityRelationsQuery query ) {
public ListenableFuture < List < EntityRelation > > findByQuery ( TenantId tenantId , EntityRelationsQuery query ) {
log . trace ( "Executing findByQuery [{}]" , query ) ;
RelationsSearchParameters params = query . getParameters ( ) ;
final List < EntityTypeFilter > filters = query . getFilters ( ) ;
@ -451,7 +453,7 @@ public class BaseRelationService implements RelationService {
int maxLvl = params . getMaxLevel ( ) > 0 ? params . getMaxLevel ( ) : Integer . MAX_VALUE ;
try {
ListenableFuture < Set < EntityRelation > > relationSet = findRelationsRecursively ( params . getEntityId ( ) , params . getDirection ( ) , params . getRelationTypeGroup ( ) , maxLvl , new ConcurrentHashMap < > ( ) ) ;
ListenableFuture < Set < EntityRelation > > relationSet = findRelationsRecursively ( tenantId , params . getEntityId ( ) , params . getDirection ( ) , params . getRelationTypeGroup ( ) , maxLvl , new ConcurrentHashMap < > ( ) ) ;
return Futures . transform ( relationSet , input - > {
List < EntityRelation > relations = new ArrayList < > ( ) ;
if ( filters = = null | | filters . isEmpty ( ) ) {
@ -472,15 +474,15 @@ public class BaseRelationService implements RelationService {
}
@Override
public ListenableFuture < List < EntityRelationInfo > > findInfoByQuery ( EntityRelationsQuery query ) {
public ListenableFuture < List < EntityRelationInfo > > findInfoByQuery ( TenantId tenantId , EntityRelationsQuery query ) {
log . trace ( "Executing findInfoByQuery [{}]" , query ) ;
ListenableFuture < List < EntityRelation > > relations = findByQuery ( query ) ;
ListenableFuture < List < EntityRelation > > relations = findByQuery ( tenantId , query ) ;
EntitySearchDirection direction = query . getParameters ( ) . getDirection ( ) ;
return Futures . transformAsync ( relations ,
relations1 - > {
List < ListenableFuture < EntityRelationInfo > > futures = new ArrayList < > ( ) ;
relations1 . forEach ( relation - >
futures . add ( fetchRelationInfoAsync ( relation ,
futures . add ( fetchRelationInfoAsync ( tenantId , relation ,
relation2 - > direction = = EntitySearchDirection . FROM ? relation2 . getTo ( ) : relation2 . getFrom ( ) ,
( EntityRelationInfo relationInfo , String entityName ) - > {
if ( direction = = EntitySearchDirection . FROM ) {
@ -567,7 +569,7 @@ public class BaseRelationService implements RelationService {
}
}
private ListenableFuture < Set < EntityRelation > > findRelationsRecursively ( final EntityId rootId , final EntitySearchDirection direction ,
private ListenableFuture < Set < EntityRelation > > findRelationsRecursively ( final TenantId tenantId , final EntityId rootId , final EntitySearchDirection direction ,
RelationTypeGroup relationTypeGroup , int lvl ,
final ConcurrentHashMap < EntityId , Boolean > uniqueMap ) throws Exception {
if ( lvl = = 0 ) {
@ -575,7 +577,7 @@ public class BaseRelationService implements RelationService {
}
lvl - - ;
//TODO: try to remove this blocking operation
Set < EntityRelation > children = new HashSet < > ( findRelations ( rootId , direction , relationTypeGroup ) . get ( ) ) ;
Set < EntityRelation > children = new HashSet < > ( findRelations ( tenantId , rootId , direction , relationTypeGroup ) . get ( ) ) ;
Set < EntityId > childrenIds = new HashSet < > ( ) ;
for ( EntityRelation childRelation : children ) {
log . trace ( "Found Relation: {}" , childRelation ) ;
@ -594,7 +596,7 @@ public class BaseRelationService implements RelationService {
}
List < ListenableFuture < Set < EntityRelation > > > futures = new ArrayList < > ( ) ;
for ( EntityId entityId : childrenIds ) {
futures . add ( findRelationsRecursively ( entityId , direction , relationTypeGroup , lvl , uniqueMap ) ) ;
futures . add ( findRelationsRecursively ( tenantId , entityId , direction , relationTypeGroup , lvl , uniqueMap ) ) ;
}
//TODO: try to remove this blocking operation
List < Set < EntityRelation > > relations = Futures . successfulAsList ( futures ) . get ( ) ;
@ -602,15 +604,15 @@ public class BaseRelationService implements RelationService {
return Futures . immediateFuture ( children ) ;
}
private ListenableFuture < List < EntityRelation > > findRelations ( final EntityId rootId , final EntitySearchDirection direction , RelationTypeGroup relationTypeGroup ) {
private ListenableFuture < List < EntityRelation > > findRelations ( final TenantId tenantId , final EntityId rootId , final EntitySearchDirection direction , RelationTypeGroup relationTypeGroup ) {
ListenableFuture < List < EntityRelation > > relations ;
if ( relationTypeGroup = = null ) {
relationTypeGroup = RelationTypeGroup . COMMON ;
}
if ( direction = = EntitySearchDirection . FROM ) {
relations = findByFromAsync ( rootId , relationTypeGroup ) ;
relations = findByFromAsync ( tenantId , rootId , relationTypeGroup ) ;
} else {
relations = findByToAsync ( rootId , relationTypeGroup ) ;
relations = findByToAsync ( tenantId , rootId , relationTypeGroup ) ;
}
return relations ;
}