|
|
@ -402,7 +402,7 @@ public class BaseRelationService implements RelationService { |
|
|
int maxLvl = params.getMaxLevel() > 0 ? params.getMaxLevel() : Integer.MAX_VALUE; |
|
|
int maxLvl = params.getMaxLevel() > 0 ? params.getMaxLevel() : Integer.MAX_VALUE; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
ListenableFuture<Set<EntityRelation>> relationSet = findRelationsRecursively(params.getEntityId(), params.getDirection(), maxLvl, new ConcurrentHashMap<>()); |
|
|
ListenableFuture<Set<EntityRelation>> relationSet = findRelationsRecursively(params.getEntityId(), params.getDirection(), params.getRelationTypeGroup(), maxLvl, new ConcurrentHashMap<>()); |
|
|
return Futures.transform(relationSet, input -> { |
|
|
return Futures.transform(relationSet, input -> { |
|
|
List<EntityRelation> relations = new ArrayList<>(); |
|
|
List<EntityRelation> relations = new ArrayList<>(); |
|
|
if (filters == null || filters.isEmpty()) { |
|
|
if (filters == null || filters.isEmpty()) { |
|
|
@ -518,14 +518,15 @@ public class BaseRelationService implements RelationService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private ListenableFuture<Set<EntityRelation>> findRelationsRecursively(final EntityId rootId, final EntitySearchDirection direction, int lvl, |
|
|
private ListenableFuture<Set<EntityRelation>> findRelationsRecursively(final EntityId rootId, final EntitySearchDirection direction, |
|
|
|
|
|
RelationTypeGroup relationTypeGroup, int lvl, |
|
|
final ConcurrentHashMap<EntityId, Boolean> uniqueMap) throws Exception { |
|
|
final ConcurrentHashMap<EntityId, Boolean> uniqueMap) throws Exception { |
|
|
if (lvl == 0) { |
|
|
if (lvl == 0) { |
|
|
return Futures.immediateFuture(Collections.emptySet()); |
|
|
return Futures.immediateFuture(Collections.emptySet()); |
|
|
} |
|
|
} |
|
|
lvl--; |
|
|
lvl--; |
|
|
//TODO: try to remove this blocking operation
|
|
|
//TODO: try to remove this blocking operation
|
|
|
Set<EntityRelation> children = new HashSet<>(findRelations(rootId, direction).get()); |
|
|
Set<EntityRelation> children = new HashSet<>(findRelations(rootId, direction, relationTypeGroup).get()); |
|
|
Set<EntityId> childrenIds = new HashSet<>(); |
|
|
Set<EntityId> childrenIds = new HashSet<>(); |
|
|
for (EntityRelation childRelation : children) { |
|
|
for (EntityRelation childRelation : children) { |
|
|
log.trace("Found Relation: {}", childRelation); |
|
|
log.trace("Found Relation: {}", childRelation); |
|
|
@ -544,7 +545,7 @@ public class BaseRelationService implements RelationService { |
|
|
} |
|
|
} |
|
|
List<ListenableFuture<Set<EntityRelation>>> futures = new ArrayList<>(); |
|
|
List<ListenableFuture<Set<EntityRelation>>> futures = new ArrayList<>(); |
|
|
for (EntityId entityId : childrenIds) { |
|
|
for (EntityId entityId : childrenIds) { |
|
|
futures.add(findRelationsRecursively(entityId, direction, lvl, uniqueMap)); |
|
|
futures.add(findRelationsRecursively(entityId, direction, relationTypeGroup, lvl, uniqueMap)); |
|
|
} |
|
|
} |
|
|
//TODO: try to remove this blocking operation
|
|
|
//TODO: try to remove this blocking operation
|
|
|
List<Set<EntityRelation>> relations = Futures.successfulAsList(futures).get(); |
|
|
List<Set<EntityRelation>> relations = Futures.successfulAsList(futures).get(); |
|
|
@ -552,12 +553,12 @@ public class BaseRelationService implements RelationService { |
|
|
return Futures.immediateFuture(children); |
|
|
return Futures.immediateFuture(children); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private ListenableFuture<List<EntityRelation>> findRelations(final EntityId rootId, final EntitySearchDirection direction) { |
|
|
private ListenableFuture<List<EntityRelation>> findRelations(final EntityId rootId, final EntitySearchDirection direction, RelationTypeGroup relationTypeGroup) { |
|
|
ListenableFuture<List<EntityRelation>> relations; |
|
|
ListenableFuture<List<EntityRelation>> relations; |
|
|
if (direction == EntitySearchDirection.FROM) { |
|
|
if (direction == EntitySearchDirection.FROM) { |
|
|
relations = findByFromAsync(rootId, RelationTypeGroup.COMMON); |
|
|
relations = findByFromAsync(rootId, relationTypeGroup); |
|
|
} else { |
|
|
} else { |
|
|
relations = findByToAsync(rootId, RelationTypeGroup.COMMON); |
|
|
relations = findByToAsync(rootId, relationTypeGroup); |
|
|
} |
|
|
} |
|
|
return relations; |
|
|
return relations; |
|
|
} |
|
|
} |
|
|
|