Commit 15d7bf7ce73844a17e55e4a7c73be3deb0d8cbd6

Authored by Andrew Shvayka
1 parent 94ef2b60

Added RelationTypeGroup to relation Query API

@@ -33,13 +33,19 @@ public class RelationsSearchParameters { @@ -33,13 +33,19 @@ public class RelationsSearchParameters {
33 private UUID rootId; 33 private UUID rootId;
34 private EntityType rootType; 34 private EntityType rootType;
35 private EntitySearchDirection direction; 35 private EntitySearchDirection direction;
  36 + private RelationTypeGroup relationTypeGroup;
36 private int maxLevel = 1; 37 private int maxLevel = 1;
37 38
38 public RelationsSearchParameters(EntityId entityId, EntitySearchDirection direction, int maxLevel) { 39 public RelationsSearchParameters(EntityId entityId, EntitySearchDirection direction, int maxLevel) {
  40 + this(entityId, direction, maxLevel, RelationTypeGroup.COMMON);
  41 + }
  42 +
  43 + public RelationsSearchParameters(EntityId entityId, EntitySearchDirection direction, int maxLevel, RelationTypeGroup relationTypeGroup) {
39 this.rootId = entityId.getId(); 44 this.rootId = entityId.getId();
40 this.rootType = entityId.getEntityType(); 45 this.rootType = entityId.getEntityType();
41 this.direction = direction; 46 this.direction = direction;
42 this.maxLevel = maxLevel; 47 this.maxLevel = maxLevel;
  48 + this.relationTypeGroup = relationTypeGroup;
43 } 49 }
44 50
45 public EntityId getEntityId() { 51 public EntityId getEntityId() {
@@ -402,7 +402,7 @@ public class BaseRelationService implements RelationService { @@ -402,7 +402,7 @@ public class BaseRelationService implements RelationService {
402 int maxLvl = params.getMaxLevel() > 0 ? params.getMaxLevel() : Integer.MAX_VALUE; 402 int maxLvl = params.getMaxLevel() > 0 ? params.getMaxLevel() : Integer.MAX_VALUE;
403 403
404 try { 404 try {
405 - ListenableFuture<Set<EntityRelation>> relationSet = findRelationsRecursively(params.getEntityId(), params.getDirection(), maxLvl, new ConcurrentHashMap<>()); 405 + ListenableFuture<Set<EntityRelation>> relationSet = findRelationsRecursively(params.getEntityId(), params.getDirection(), params.getRelationTypeGroup(), maxLvl, new ConcurrentHashMap<>());
406 return Futures.transform(relationSet, input -> { 406 return Futures.transform(relationSet, input -> {
407 List<EntityRelation> relations = new ArrayList<>(); 407 List<EntityRelation> relations = new ArrayList<>();
408 if (filters == null || filters.isEmpty()) { 408 if (filters == null || filters.isEmpty()) {
@@ -518,14 +518,15 @@ public class BaseRelationService implements RelationService { @@ -518,14 +518,15 @@ public class BaseRelationService implements RelationService {
518 } 518 }
519 } 519 }
520 520
521 - private ListenableFuture<Set<EntityRelation>> findRelationsRecursively(final EntityId rootId, final EntitySearchDirection direction, int lvl, 521 + private ListenableFuture<Set<EntityRelation>> findRelationsRecursively(final EntityId rootId, final EntitySearchDirection direction,
  522 + RelationTypeGroup relationTypeGroup, int lvl,
522 final ConcurrentHashMap<EntityId, Boolean> uniqueMap) throws Exception { 523 final ConcurrentHashMap<EntityId, Boolean> uniqueMap) throws Exception {
523 if (lvl == 0) { 524 if (lvl == 0) {
524 return Futures.immediateFuture(Collections.emptySet()); 525 return Futures.immediateFuture(Collections.emptySet());
525 } 526 }
526 lvl--; 527 lvl--;
527 //TODO: try to remove this blocking operation 528 //TODO: try to remove this blocking operation
528 - Set<EntityRelation> children = new HashSet<>(findRelations(rootId, direction).get()); 529 + Set<EntityRelation> children = new HashSet<>(findRelations(rootId, direction, relationTypeGroup).get());
529 Set<EntityId> childrenIds = new HashSet<>(); 530 Set<EntityId> childrenIds = new HashSet<>();
530 for (EntityRelation childRelation : children) { 531 for (EntityRelation childRelation : children) {
531 log.trace("Found Relation: {}", childRelation); 532 log.trace("Found Relation: {}", childRelation);
@@ -544,7 +545,7 @@ public class BaseRelationService implements RelationService { @@ -544,7 +545,7 @@ public class BaseRelationService implements RelationService {
544 } 545 }
545 List<ListenableFuture<Set<EntityRelation>>> futures = new ArrayList<>(); 546 List<ListenableFuture<Set<EntityRelation>>> futures = new ArrayList<>();
546 for (EntityId entityId : childrenIds) { 547 for (EntityId entityId : childrenIds) {
547 - futures.add(findRelationsRecursively(entityId, direction, lvl, uniqueMap)); 548 + futures.add(findRelationsRecursively(entityId, direction, relationTypeGroup, lvl, uniqueMap));
548 } 549 }
549 //TODO: try to remove this blocking operation 550 //TODO: try to remove this blocking operation
550 List<Set<EntityRelation>> relations = Futures.successfulAsList(futures).get(); 551 List<Set<EntityRelation>> relations = Futures.successfulAsList(futures).get();
@@ -552,12 +553,12 @@ public class BaseRelationService implements RelationService { @@ -552,12 +553,12 @@ public class BaseRelationService implements RelationService {
552 return Futures.immediateFuture(children); 553 return Futures.immediateFuture(children);
553 } 554 }
554 555
555 - private ListenableFuture<List<EntityRelation>> findRelations(final EntityId rootId, final EntitySearchDirection direction) { 556 + private ListenableFuture<List<EntityRelation>> findRelations(final EntityId rootId, final EntitySearchDirection direction, RelationTypeGroup relationTypeGroup) {
556 ListenableFuture<List<EntityRelation>> relations; 557 ListenableFuture<List<EntityRelation>> relations;
557 if (direction == EntitySearchDirection.FROM) { 558 if (direction == EntitySearchDirection.FROM) {
558 - relations = findByFromAsync(rootId, RelationTypeGroup.COMMON); 559 + relations = findByFromAsync(rootId, relationTypeGroup);
559 } else { 560 } else {
560 - relations = findByToAsync(rootId, RelationTypeGroup.COMMON); 561 + relations = findByToAsync(rootId, relationTypeGroup);
561 } 562 }
562 return relations; 563 return relations;
563 } 564 }