|
|
|
@ -29,6 +29,8 @@ import org.thingsboard.server.common.data.query.AssetSearchQueryFilter; |
|
|
|
import org.thingsboard.server.common.data.query.AssetTypeFilter; |
|
|
|
import org.thingsboard.server.common.data.query.DeviceSearchQueryFilter; |
|
|
|
import org.thingsboard.server.common.data.query.DeviceTypeFilter; |
|
|
|
import org.thingsboard.server.common.data.query.EdgeSearchQueryFilter; |
|
|
|
import org.thingsboard.server.common.data.query.EdgeTypeFilter; |
|
|
|
import org.thingsboard.server.common.data.query.EntityCountQuery; |
|
|
|
import org.thingsboard.server.common.data.query.EntityData; |
|
|
|
import org.thingsboard.server.common.data.query.EntityDataPageLink; |
|
|
|
@ -111,6 +113,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select customer_id from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select customer_id from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select customer_id from edge where id = entity_id)" + |
|
|
|
" END as customer_id"; |
|
|
|
private static final String SELECT_TENANT_ID = "SELECT CASE" + |
|
|
|
" WHEN entity.entity_type = 'TENANT' THEN entity_id" + |
|
|
|
@ -126,6 +130,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select tenant_id from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select tenant_id from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select tenant_id from edge where id = entity_id)" + |
|
|
|
" END as tenant_id"; |
|
|
|
private static final String SELECT_CREATED_TIME = " CASE" + |
|
|
|
" WHEN entity.entity_type = 'TENANT'" + |
|
|
|
@ -142,6 +148,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select created_time from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select created_time from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select created_time from edge where id = entity_id)" + |
|
|
|
" END as created_time"; |
|
|
|
private static final String SELECT_NAME = " CASE" + |
|
|
|
" WHEN entity.entity_type = 'TENANT'" + |
|
|
|
@ -158,6 +166,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select name from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select name from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select name from edge where id = entity_id)" + |
|
|
|
" END as name"; |
|
|
|
private static final String SELECT_TYPE = " CASE" + |
|
|
|
" WHEN entity.entity_type = 'USER'" + |
|
|
|
@ -168,6 +178,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select type from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select type from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select type from edge where id = entity_id)" + |
|
|
|
" ELSE entity.entity_type END as type"; |
|
|
|
private static final String SELECT_LABEL = " CASE" + |
|
|
|
" WHEN entity.entity_type = 'TENANT'" + |
|
|
|
@ -184,6 +196,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select label from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select name from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select label from edge where id = entity_id)" + |
|
|
|
" END as label"; |
|
|
|
private static final String SELECT_ADDITIONAL_INFO = " CASE" + |
|
|
|
" WHEN entity.entity_type = 'TENANT'" + |
|
|
|
@ -200,6 +214,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
" THEN (select additional_info from device where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'ENTITY_VIEW'" + |
|
|
|
" THEN (select additional_info from entity_view where id = entity_id)" + |
|
|
|
" WHEN entity.entity_type = 'EDGE'" + |
|
|
|
" THEN (select additional_info from edge where id = entity_id)" + |
|
|
|
" END as additional_info"; |
|
|
|
|
|
|
|
private static final String SELECT_API_USAGE_STATE = "(select aus.id, aus.created_time, aus.tenant_id, '13814000-1dd2-11b2-8080-808080808080'::uuid as customer_id, " + |
|
|
|
@ -214,6 +230,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
entityTableMap.put(EntityType.USER, "tb_user"); |
|
|
|
entityTableMap.put(EntityType.TENANT, "tenant"); |
|
|
|
entityTableMap.put(EntityType.API_USAGE_STATE, SELECT_API_USAGE_STATE); |
|
|
|
entityTableMap.put(EntityType.EDGE, "edge"); |
|
|
|
} |
|
|
|
|
|
|
|
public static EntityType[] RELATION_QUERY_ENTITY_TYPES = new EntityType[]{ |
|
|
|
@ -394,6 +411,7 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
case DEVICE_SEARCH_QUERY: |
|
|
|
case ASSET_SEARCH_QUERY: |
|
|
|
case ENTITY_VIEW_SEARCH_QUERY: |
|
|
|
case EDGE_SEARCH_QUERY: |
|
|
|
return this.defaultPermissionQuery(ctx); |
|
|
|
default: |
|
|
|
if (ctx.getEntityType() == EntityType.TENANT) { |
|
|
|
@ -430,11 +448,13 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
case ASSET_TYPE: |
|
|
|
case DEVICE_TYPE: |
|
|
|
case ENTITY_VIEW_TYPE: |
|
|
|
case EDGE_TYPE: |
|
|
|
return this.typeQuery(ctx, entityFilter); |
|
|
|
case RELATIONS_QUERY: |
|
|
|
case DEVICE_SEARCH_QUERY: |
|
|
|
case ASSET_SEARCH_QUERY: |
|
|
|
case ENTITY_VIEW_SEARCH_QUERY: |
|
|
|
case EDGE_SEARCH_QUERY: |
|
|
|
case API_USAGE_STATE: |
|
|
|
return ""; |
|
|
|
default: |
|
|
|
@ -455,6 +475,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
case ENTITY_VIEW_SEARCH_QUERY: |
|
|
|
EntityViewSearchQueryFilter entityViewQuery = (EntityViewSearchQueryFilter) entityFilter; |
|
|
|
return entitySearchQuery(ctx, entityViewQuery, EntityType.ENTITY_VIEW, entityViewQuery.getEntityViewTypes()); |
|
|
|
case EDGE_SEARCH_QUERY: |
|
|
|
EdgeSearchQueryFilter edgeQuery = (EdgeSearchQueryFilter) entityFilter; |
|
|
|
return entitySearchQuery(ctx, edgeQuery, EntityType.EDGE, edgeQuery.getEdgeTypes()); |
|
|
|
default: |
|
|
|
return entityTableMap.get(ctx.getEntityType()); |
|
|
|
} |
|
|
|
@ -660,6 +683,10 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
type = ((EntityViewTypeFilter) filter).getEntityViewType(); |
|
|
|
name = ((EntityViewTypeFilter) filter).getEntityViewNameFilter(); |
|
|
|
break; |
|
|
|
case EDGE_TYPE: |
|
|
|
type = ((EdgeTypeFilter) filter).getEdgeType(); |
|
|
|
name = ((EdgeTypeFilter) filter).getEdgeNameFilter(); |
|
|
|
break; |
|
|
|
default: |
|
|
|
throw new RuntimeException("Not supported!"); |
|
|
|
} |
|
|
|
@ -685,6 +712,9 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
case ENTITY_VIEW_TYPE: |
|
|
|
case ENTITY_VIEW_SEARCH_QUERY: |
|
|
|
return EntityType.ENTITY_VIEW; |
|
|
|
case EDGE_TYPE: |
|
|
|
case EDGE_SEARCH_QUERY: |
|
|
|
return EntityType.EDGE; |
|
|
|
case RELATIONS_QUERY: |
|
|
|
return ((RelationsQueryFilter) entityFilter).getRootEntity().getEntityType(); |
|
|
|
case API_USAGE_STATE: |
|
|
|
|