Commit 15d7bf7ce73844a17e55e4a7c73be3deb0d8cbd6

Authored by Andrew Shvayka
1 parent 94ef2b60

Added RelationTypeGroup to relation Query API

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