Merge pull request #13560 from volodymyr-babak/edqs-relations-fix
EDQS - fixed relations query in case multiple previous path are present
This commit is contained in:
		
						commit
						13268cfcc1
					
				@ -15,6 +15,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
package org.thingsboard.server.edqs.query.processor;
 | 
					package org.thingsboard.server.edqs.query.processor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import lombok.EqualsAndHashCode;
 | 
				
			||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import org.thingsboard.server.common.data.permission.QueryContext;
 | 
					import org.thingsboard.server.common.data.permission.QueryContext;
 | 
				
			||||||
import org.thingsboard.server.common.data.query.EntityFilter;
 | 
					import org.thingsboard.server.common.data.query.EntityFilter;
 | 
				
			||||||
@ -106,7 +107,7 @@ public abstract class AbstractRelationQueryProcessor<T extends EntityFilter> ext
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private Set<EntityData<?>> getEntitiesSet(RelationsRepo relations) {
 | 
					    private Set<EntityData<?>> getEntitiesSet(RelationsRepo relations) {
 | 
				
			||||||
        Set<EntityData<?>> result = new HashSet<>();
 | 
					        Set<EntityData<?>> result = new HashSet<>();
 | 
				
			||||||
        Set<UUID> processed = new HashSet<>();
 | 
					        Set<RelationSearchTask> processed = new HashSet<>();
 | 
				
			||||||
        Queue<RelationSearchTask> tasks = new LinkedList<>();
 | 
					        Queue<RelationSearchTask> tasks = new LinkedList<>();
 | 
				
			||||||
        int maxLvl = getMaxLevel() == 0 ? MAXIMUM_QUERY_LEVEL : Math.max(1, getMaxLevel());
 | 
					        int maxLvl = getMaxLevel() == 0 ? MAXIMUM_QUERY_LEVEL : Math.max(1, getMaxLevel());
 | 
				
			||||||
        for (UUID uuid : getRootEntities()) {
 | 
					        for (UUID uuid : getRootEntities()) {
 | 
				
			||||||
@ -114,7 +115,7 @@ public abstract class AbstractRelationQueryProcessor<T extends EntityFilter> ext
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        while (!tasks.isEmpty()) {
 | 
					        while (!tasks.isEmpty()) {
 | 
				
			||||||
            RelationSearchTask task = tasks.poll();
 | 
					            RelationSearchTask task = tasks.poll();
 | 
				
			||||||
            if (processed.add(task.entityId)) {
 | 
					            if (processed.add(task)) {
 | 
				
			||||||
                var entityLvl = task.lvl + 1;
 | 
					                var entityLvl = task.lvl + 1;
 | 
				
			||||||
                Set<RelationInfo> entities = EntitySearchDirection.FROM.equals(getDirection()) ? relations.getFrom(task.entityId) : relations.getTo(task.entityId);
 | 
					                Set<RelationInfo> entities = EntitySearchDirection.FROM.equals(getDirection()) ? relations.getFrom(task.entityId) : relations.getTo(task.entityId);
 | 
				
			||||||
                if (isFetchLastLevelOnly() && entities.isEmpty() && task.previous != null && check(task.previous)) {
 | 
					                if (isFetchLastLevelOnly() && entities.isEmpty() && task.previous != null && check(task.previous)) {
 | 
				
			||||||
@ -157,6 +158,7 @@ public abstract class AbstractRelationQueryProcessor<T extends EntityFilter> ext
 | 
				
			|||||||
    protected abstract boolean check(RelationInfo relationInfo);
 | 
					    protected abstract boolean check(RelationInfo relationInfo);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @RequiredArgsConstructor
 | 
					    @RequiredArgsConstructor
 | 
				
			||||||
 | 
					    @EqualsAndHashCode
 | 
				
			||||||
    private static class RelationSearchTask {
 | 
					    private static class RelationSearchTask {
 | 
				
			||||||
        private final UUID entityId;
 | 
					        private final UUID entityId;
 | 
				
			||||||
        private final int lvl;
 | 
					        private final int lvl;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user