Commit e781dd0718ea3b25f8a08ebf46fa2f60dac2f213
Committed by
GitHub
Merge pull request #1070 from ViktorBasanets/master
Merge
Showing
14 changed files
with
82 additions
and
54 deletions
@@ -29,8 +29,8 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | @@ -29,8 +29,8 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | ||
29 | customer_id timeuuid, | 29 | customer_id timeuuid, |
30 | name text, | 30 | name text, |
31 | keys text, | 31 | keys text, |
32 | - ts_begin bigint, | ||
33 | - ts_end bigint, | 32 | + start_ts bigint, |
33 | + end_ts bigint, | ||
34 | search_text text, | 34 | search_text text, |
35 | additional_info text, | 35 | additional_info text, |
36 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) | 36 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) |
@@ -43,8 +43,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_na | @@ -43,8 +43,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_na | ||
43 | AND tenant_id IS NOT NULL | 43 | AND tenant_id IS NOT NULL |
44 | AND customer_id IS NOT NULL | 44 | AND customer_id IS NOT NULL |
45 | AND keys IS NOT NULL | 45 | AND keys IS NOT NULL |
46 | - AND ts_begin IS NOT NULL | ||
47 | - AND ts_end IS NOT NULL | 46 | + AND start_ts IS NOT NULL |
47 | + AND end_ts IS NOT NULL | ||
48 | AND name IS NOT NULL | 48 | AND name IS NOT NULL |
49 | AND id IS NOT NULL | 49 | AND id IS NOT NULL |
50 | PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) | 50 | PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) |
@@ -57,8 +57,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_en | @@ -57,8 +57,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_en | ||
57 | AND tenant_id IS NOT NULL | 57 | AND tenant_id IS NOT NULL |
58 | AND customer_id IS NOT NULL | 58 | AND customer_id IS NOT NULL |
59 | AND keys IS NOT NULL | 59 | AND keys IS NOT NULL |
60 | - AND ts_begin IS NOT NULL | ||
61 | - AND ts_end IS NOT NULL | 60 | + AND start_ts IS NOT NULL |
61 | + AND end_ts IS NOT NULL | ||
62 | AND name IS NOT NULL | 62 | AND name IS NOT NULL |
63 | AND id IS NOT NULL | 63 | AND id IS NOT NULL |
64 | PRIMARY KEY (tenant_id, entity_id, id, customer_id, name) | 64 | PRIMARY KEY (tenant_id, entity_id, id, customer_id, name) |
@@ -71,8 +71,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | @@ -71,8 +71,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | ||
71 | AND tenant_id IS NOT NULL | 71 | AND tenant_id IS NOT NULL |
72 | AND customer_id IS NOT NULL | 72 | AND customer_id IS NOT NULL |
73 | AND keys IS NOT NULL | 73 | AND keys IS NOT NULL |
74 | - AND ts_begin IS NOT NULL | ||
75 | - AND ts_end IS NOT NULL | 74 | + AND start_ts IS NOT NULL |
75 | + AND end_ts IS NOT NULL | ||
76 | AND name IS NOT NULL | 76 | AND name IS NOT NULL |
77 | AND id IS NOT NULL | 77 | AND id IS NOT NULL |
78 | PRIMARY KEY (tenant_id, customer_id, id, entity_id, name) | 78 | PRIMARY KEY (tenant_id, customer_id, id, entity_id, name) |
@@ -85,8 +85,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | @@ -85,8 +85,8 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | ||
85 | AND tenant_id IS NOT NULL | 85 | AND tenant_id IS NOT NULL |
86 | AND customer_id IS NOT NULL | 86 | AND customer_id IS NOT NULL |
87 | AND keys IS NOT NULL | 87 | AND keys IS NOT NULL |
88 | - AND ts_begin IS NOT NULL | ||
89 | - AND ts_end IS NOT NULL | 88 | + AND start_ts IS NOT NULL |
89 | + AND end_ts IS NOT NULL | ||
90 | AND name IS NOT NULL | 90 | AND name IS NOT NULL |
91 | AND id IS NOT NULL | 91 | AND id IS NOT NULL |
92 | PRIMARY KEY (tenant_id, customer_id, entity_id, id, name) | 92 | PRIMARY KEY (tenant_id, customer_id, entity_id, id, name) |
@@ -24,8 +24,8 @@ CREATE TABLE IF NOT EXISTS entity_views ( | @@ -24,8 +24,8 @@ CREATE TABLE IF NOT EXISTS entity_views ( | ||
24 | customer_id varchar(31), | 24 | customer_id varchar(31), |
25 | name varchar(255), | 25 | name varchar(255), |
26 | keys varchar(255), | 26 | keys varchar(255), |
27 | - ts_begin varchar(255), | ||
28 | - ts_end varchar(255), | 27 | + start_ts bigint, |
28 | + end_ts bigint, | ||
29 | search_text varchar(255), | 29 | search_text varchar(255), |
30 | additional_info varchar | 30 | additional_info varchar |
31 | ); | 31 | ); |
@@ -29,10 +29,15 @@ import org.thingsboard.rule.engine.api.util.DonAsynchron; | @@ -29,10 +29,15 @@ import org.thingsboard.rule.engine.api.util.DonAsynchron; | ||
29 | import org.thingsboard.server.actors.service.ActorService; | 29 | import org.thingsboard.server.actors.service.ActorService; |
30 | import org.thingsboard.server.common.data.DataConstants; | 30 | import org.thingsboard.server.common.data.DataConstants; |
31 | import org.thingsboard.server.common.data.EntityType; | 31 | import org.thingsboard.server.common.data.EntityType; |
32 | +import org.thingsboard.server.common.data.EntityView; | ||
32 | import org.thingsboard.server.common.data.id.DeviceId; | 33 | import org.thingsboard.server.common.data.id.DeviceId; |
33 | import org.thingsboard.server.common.data.id.EntityId; | 34 | import org.thingsboard.server.common.data.id.EntityId; |
34 | import org.thingsboard.server.common.data.id.EntityIdFactory; | 35 | import org.thingsboard.server.common.data.id.EntityIdFactory; |
36 | +//<<<<<<< HEAD | ||
37 | +import org.thingsboard.server.common.data.id.EntityViewId; | ||
38 | +//======= | ||
35 | import org.thingsboard.server.common.data.id.TenantId; | 39 | import org.thingsboard.server.common.data.id.TenantId; |
40 | +//>>>>>>> d909192071880b7af2137333142bc62ece369ec1 | ||
36 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 41 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
37 | import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | 42 | import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; |
38 | import org.thingsboard.server.common.data.kv.BaseReadTsKvQuery; | 43 | import org.thingsboard.server.common.data.kv.BaseReadTsKvQuery; |
@@ -48,6 +53,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | @@ -48,6 +53,8 @@ import org.thingsboard.server.common.data.kv.TsKvEntry; | ||
48 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; | 53 | import org.thingsboard.server.common.msg.cluster.SendToClusterMsg; |
49 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 54 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
50 | import org.thingsboard.server.dao.attributes.AttributesService; | 55 | import org.thingsboard.server.dao.attributes.AttributesService; |
56 | +import org.thingsboard.server.dao.entityview.EntityViewService; | ||
57 | +import org.thingsboard.server.dao.model.ModelConstants; | ||
51 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 58 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
52 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 59 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
53 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; | 60 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; |
@@ -101,6 +108,9 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | @@ -101,6 +108,9 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | ||
101 | @Autowired | 108 | @Autowired |
102 | private ClusterRpcService rpcService; | 109 | private ClusterRpcService rpcService; |
103 | 110 | ||
111 | + /*@Autowired | ||
112 | + private EntityViewService entityViewService;*/ | ||
113 | + | ||
104 | @Autowired | 114 | @Autowired |
105 | @Lazy | 115 | @Lazy |
106 | private DeviceStateService stateService; | 116 | private DeviceStateService stateService; |
@@ -133,15 +143,17 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | @@ -133,15 +143,17 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio | ||
133 | 143 | ||
134 | @Override | 144 | @Override |
135 | public void addLocalWsSubscription(String sessionId, EntityId entityId, SubscriptionState sub) { | 145 | public void addLocalWsSubscription(String sessionId, EntityId entityId, SubscriptionState sub) { |
146 | + String familyName = entityId.getEntityType().equals(EntityType.ENTITY_VIEW) | ||
147 | + ? ModelConstants.ENTITY_VIEW_FAMILY_NAME : ModelConstants.DEVICE_FAMILY_NAME; | ||
136 | Optional<ServerAddress> server = routingService.resolveById(entityId); | 148 | Optional<ServerAddress> server = routingService.resolveById(entityId); |
137 | Subscription subscription; | 149 | Subscription subscription; |
138 | if (server.isPresent()) { | 150 | if (server.isPresent()) { |
139 | ServerAddress address = server.get(); | 151 | ServerAddress address = server.get(); |
140 | - log.trace("[{}] Forwarding subscription [{}] for device [{}] to [{}]", sessionId, sub.getSubscriptionId(), entityId, address); | 152 | + log.trace("[{}] Forwarding subscription [{}] for " + familyName + " [{}] to [{}]", sessionId, sub.getSubscriptionId(), entityId, address); |
141 | subscription = new Subscription(sub, true, address); | 153 | subscription = new Subscription(sub, true, address); |
142 | tellNewSubscription(address, sessionId, subscription); | 154 | tellNewSubscription(address, sessionId, subscription); |
143 | } else { | 155 | } else { |
144 | - log.trace("[{}] Registering local subscription [{}] for device [{}]", sessionId, sub.getSubscriptionId(), entityId); | 156 | + log.trace("[{}] Registering local subscription [{}] for " + familyName + " [{}]", sessionId, sub.getSubscriptionId(), entityId); |
145 | subscription = new Subscription(sub, true); | 157 | subscription = new Subscription(sub, true); |
146 | } | 158 | } |
147 | registerSubscription(sessionId, entityId, subscription); | 159 | registerSubscription(sessionId, entityId, subscription); |
@@ -30,9 +30,15 @@ public class Subscription { | @@ -30,9 +30,15 @@ public class Subscription { | ||
30 | private final SubscriptionState sub; | 30 | private final SubscriptionState sub; |
31 | private final boolean local; | 31 | private final boolean local; |
32 | private ServerAddress server; | 32 | private ServerAddress server; |
33 | + private long startTime; | ||
34 | + private long endTime; | ||
33 | 35 | ||
34 | public Subscription(SubscriptionState sub, boolean local) { | 36 | public Subscription(SubscriptionState sub, boolean local) { |
35 | - this(sub, local, null); | 37 | + this(sub, local, null, 0L, 0L); |
38 | + } | ||
39 | + | ||
40 | + public Subscription(SubscriptionState sub, boolean local, ServerAddress server) { | ||
41 | + this(sub, local, server, 0L, 0L); | ||
36 | } | 42 | } |
37 | 43 | ||
38 | public String getWsSessionId() { | 44 | public String getWsSessionId() { |
@@ -24,7 +24,7 @@ import java.util.Arrays; | @@ -24,7 +24,7 @@ import java.util.Arrays; | ||
24 | 24 | ||
25 | @RunWith(ClasspathSuite.class) | 25 | @RunWith(ClasspathSuite.class) |
26 | @ClasspathSuite.ClassnameFilters({ | 26 | @ClasspathSuite.ClassnameFilters({ |
27 | - "org.thingsboard.server.controller.sql.*Test", | 27 | + "org.thingsboard.server.controller.sql.EntityViewControllerSqlTest", |
28 | }) | 28 | }) |
29 | public class ControllerSqlTestSuite { | 29 | public class ControllerSqlTestSuite { |
30 | 30 |
@@ -42,4 +42,8 @@ public class BaseReadTsKvQuery extends BaseTsKvQuery implements ReadTsKvQuery { | @@ -42,4 +42,8 @@ public class BaseReadTsKvQuery extends BaseTsKvQuery implements ReadTsKvQuery { | ||
42 | this(key, startTs, endTs, endTs - startTs, 1, Aggregation.AVG, "DESC"); | 42 | this(key, startTs, endTs, endTs - startTs, 1, Aggregation.AVG, "DESC"); |
43 | } | 43 | } |
44 | 44 | ||
45 | + public BaseReadTsKvQuery(String key, long startTs, long endTs, int limit, String orderBy) { | ||
46 | + this(key, startTs, endTs, endTs - startTs, limit, Aggregation.AVG, orderBy); | ||
47 | + } | ||
48 | + | ||
45 | } | 49 | } |
@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
24 | import org.springframework.cache.Cache; | 24 | import org.springframework.cache.Cache; |
25 | import org.springframework.cache.CacheManager; | 25 | import org.springframework.cache.CacheManager; |
26 | import org.springframework.cache.annotation.CacheEvict; | 26 | import org.springframework.cache.annotation.CacheEvict; |
27 | +import org.springframework.cache.annotation.CachePut; | ||
27 | import org.springframework.cache.annotation.Cacheable; | 28 | import org.springframework.cache.annotation.Cacheable; |
28 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
29 | import org.thingsboard.server.common.data.Customer; | 30 | import org.thingsboard.server.common.data.Customer; |
@@ -88,7 +89,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -88,7 +89,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
88 | @Autowired | 89 | @Autowired |
89 | private CacheManager cacheManager; | 90 | private CacheManager cacheManager; |
90 | 91 | ||
91 | -// @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}") | 92 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE) |
92 | @Override | 93 | @Override |
93 | public EntityView findEntityViewById(EntityViewId entityViewId) { | 94 | public EntityView findEntityViewById(EntityViewId entityViewId) { |
94 | log.trace("Executing findEntityViewById [{}]", entityViewId); | 95 | log.trace("Executing findEntityViewById [{}]", entityViewId); |
@@ -104,7 +105,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -104,7 +105,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
104 | .orElse(null); | 105 | .orElse(null); |
105 | } | 106 | } |
106 | 107 | ||
107 | -// @CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityView.id}") | 108 | + @CachePut(cacheNames = ENTITY_VIEW_CACHE) |
108 | @Override | 109 | @Override |
109 | public EntityView saveEntityView(EntityView entityView) { | 110 | public EntityView saveEntityView(EntityView entityView) { |
110 | log.trace("Executing save entity view [{}]", entityView); | 111 | log.trace("Executing save entity view [{}]", entityView); |
@@ -136,7 +137,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -136,7 +137,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
136 | List<Object> list = new ArrayList<>(); | 137 | List<Object> list = new ArrayList<>(); |
137 | list.add(entityView.getTenantId()); | 138 | list.add(entityView.getTenantId()); |
138 | list.add(entityView.getName()); | 139 | list.add(entityView.getName()); |
139 | -// cache.evict(list); | 140 | + cache.evict(list); |
140 | entityViewDao.removeById(entityViewId.getId()); | 141 | entityViewDao.removeById(entityViewId.getId()); |
141 | } | 142 | } |
142 | 143 | ||
@@ -149,7 +150,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -149,7 +150,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
149 | return new TextPageData<>(entityViews, pageLink); | 150 | return new TextPageData<>(entityViews, pageLink); |
150 | } | 151 | } |
151 | 152 | ||
152 | -// @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #entityId, #pageLink}") | 153 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE) |
153 | @Override | 154 | @Override |
154 | public TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, | 155 | public TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, |
155 | TextPageLink pageLink) { | 156 | TextPageLink pageLink) { |
@@ -189,7 +190,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -189,7 +190,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
189 | return new TextPageData<>(entityViews, pageLink); | 190 | return new TextPageData<>(entityViews, pageLink); |
190 | } | 191 | } |
191 | 192 | ||
192 | -// @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #customerId, #entityId, #pageLink}") | 193 | + @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #customerId, #entityId, #pageLink}") |
193 | @Override | 194 | @Override |
194 | public TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, | 195 | public TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, |
195 | CustomerId customerId, | 196 | CustomerId customerId, |
@@ -131,6 +131,7 @@ public class ModelConstants { | @@ -131,6 +131,7 @@ public class ModelConstants { | ||
131 | * Cassandra device constants. | 131 | * Cassandra device constants. |
132 | */ | 132 | */ |
133 | public static final String DEVICE_COLUMN_FAMILY_NAME = "device"; | 133 | public static final String DEVICE_COLUMN_FAMILY_NAME = "device"; |
134 | + public static final String DEVICE_FAMILY_NAME = "device"; | ||
134 | public static final String DEVICE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | 135 | public static final String DEVICE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; |
135 | public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; | 136 | public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
136 | public static final String DEVICE_NAME_PROPERTY = "name"; | 137 | public static final String DEVICE_NAME_PROPERTY = "name"; |
@@ -147,6 +148,7 @@ public class ModelConstants { | @@ -147,6 +148,7 @@ public class ModelConstants { | ||
147 | * Cassandra entityView constants. | 148 | * Cassandra entityView constants. |
148 | */ | 149 | */ |
149 | public static final String ENTITY_VIEW_TABLE_FAMILY_NAME = "entity_views"; | 150 | public static final String ENTITY_VIEW_TABLE_FAMILY_NAME = "entity_views"; |
151 | + public static final String ENTITY_VIEW_FAMILY_NAME = "entity-view"; | ||
150 | public static final String ENTITY_VIEW_ENTITY_ID_PROPERTY = ENTITY_ID_COLUMN; | 152 | public static final String ENTITY_VIEW_ENTITY_ID_PROPERTY = ENTITY_ID_COLUMN; |
151 | public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | 153 | public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; |
152 | public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; | 154 | public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
@@ -154,8 +156,8 @@ public class ModelConstants { | @@ -154,8 +156,8 @@ public class ModelConstants { | ||
154 | public static final String ENTITY_VIEW_TYPE_PROPERTY = DEVICE_TYPE_PROPERTY; | 156 | public static final String ENTITY_VIEW_TYPE_PROPERTY = DEVICE_TYPE_PROPERTY; |
155 | public static final String ENTITY_VIEW_TENANT_AND_NAME_VIEW_NAME = "entity_view_by_tenant_and_name"; | 157 | public static final String ENTITY_VIEW_TENANT_AND_NAME_VIEW_NAME = "entity_view_by_tenant_and_name"; |
156 | public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys"; | 158 | public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys"; |
157 | - public static final String ENTITY_VIEW_TS_BEGIN_PROPERTY = "ts_begin"; | ||
158 | - public static final String ENTITY_VIEW_TS_END_PROPERTY = "ts_end"; | 159 | + public static final String ENTITY_VIEW_START_TS_PROPERTY = "start_ts"; |
160 | + public static final String ENTITY_VIEW_END_TS_PROPERTY = "end_ts"; | ||
159 | public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; | 161 | public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; |
160 | public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text"; | 162 | public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text"; |
161 | 163 |
@@ -75,11 +75,11 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | @@ -75,11 +75,11 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | ||
75 | @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY) | 75 | @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY) |
76 | private String keys; | 76 | private String keys; |
77 | 77 | ||
78 | - @Column(name = ModelConstants.ENTITY_VIEW_TS_BEGIN_PROPERTY) | ||
79 | - private String tsBegin; | 78 | + @Column(name = ModelConstants.ENTITY_VIEW_START_TS_PROPERTY) |
79 | + private long startTs; | ||
80 | 80 | ||
81 | - @Column(name = ModelConstants.ENTITY_VIEW_TS_END_PROPERTY) | ||
82 | - private String tsEnd; | 81 | + @Column(name = ModelConstants.ENTITY_VIEW_END_TS_PROPERTY) |
82 | + private long endTs; | ||
83 | 83 | ||
84 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | 84 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
85 | private String searchText; | 85 | private String searchText; |
@@ -114,8 +114,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | @@ -114,8 +114,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | ||
114 | } catch (IOException e) { | 114 | } catch (IOException e) { |
115 | e.printStackTrace(); | 115 | e.printStackTrace(); |
116 | } | 116 | } |
117 | - this.tsBegin = entityView.getStartTs() != 0L ? String.valueOf(entityView.getStartTs()) : "0"; | ||
118 | - this.tsEnd = entityView.getEndTs() != 0L ? String.valueOf(entityView.getEndTs()) : "0"; | 117 | + this.startTs = entityView.getStartTs() != 0L ? entityView.getStartTs() : 0L; |
118 | + this.endTs = entityView.getEndTs() != 0L ? entityView.getEndTs() : 0L; | ||
119 | this.searchText = entityView.getSearchText(); | 119 | this.searchText = entityView.getSearchText(); |
120 | this.additionalInfo = entityView.getAdditionalInfo(); | 120 | this.additionalInfo = entityView.getAdditionalInfo(); |
121 | } | 121 | } |
@@ -144,8 +144,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | @@ -144,8 +144,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | ||
144 | } catch (IOException e) { | 144 | } catch (IOException e) { |
145 | e.printStackTrace(); | 145 | e.printStackTrace(); |
146 | } | 146 | } |
147 | - entityView.setStartTs(Long.parseLong(tsBegin)); | ||
148 | - entityView.setEndTs(Long.parseLong(tsEnd)); | 147 | + entityView.setStartTs(startTs); |
148 | + entityView.setEndTs(endTs); | ||
149 | entityView.setAdditionalInfo(additionalInfo); | 149 | entityView.setAdditionalInfo(additionalInfo); |
150 | return entityView; | 150 | return entityView; |
151 | } | 151 | } |
@@ -66,11 +66,11 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | @@ -66,11 +66,11 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | ||
66 | @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY) | 66 | @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY) |
67 | private String keys; | 67 | private String keys; |
68 | 68 | ||
69 | - @Column(name = ModelConstants.ENTITY_VIEW_TS_BEGIN_PROPERTY) | ||
70 | - private String tsBegin; | 69 | + @Column(name = ModelConstants.ENTITY_VIEW_START_TS_PROPERTY) |
70 | + private long startTs; | ||
71 | 71 | ||
72 | - @Column(name = ModelConstants.ENTITY_VIEW_TS_END_PROPERTY) | ||
73 | - private String tsEnd; | 72 | + @Column(name = ModelConstants.ENTITY_VIEW_END_TS_PROPERTY) |
73 | + private long endTs; | ||
74 | 74 | ||
75 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) | 75 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
76 | private String searchText; | 76 | private String searchText; |
@@ -105,8 +105,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | @@ -105,8 +105,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | ||
105 | } catch (IOException e) { | 105 | } catch (IOException e) { |
106 | e.printStackTrace(); | 106 | e.printStackTrace(); |
107 | } | 107 | } |
108 | - this.tsBegin = entityView.getStartTs() != 0L ? String.valueOf(entityView.getStartTs()) : "0"; | ||
109 | - this.tsEnd = entityView.getEndTs() != 0L ? String.valueOf(entityView.getEndTs()) : "0"; | 108 | + this.startTs = entityView.getStartTs() != 0L ? entityView.getStartTs() : 0L; |
109 | + this.endTs = entityView.getEndTs() != 0L ? entityView.getEndTs() : 0L; | ||
110 | this.searchText = entityView.getSearchText(); | 110 | this.searchText = entityView.getSearchText(); |
111 | this.additionalInfo = entityView.getAdditionalInfo(); | 111 | this.additionalInfo = entityView.getAdditionalInfo(); |
112 | } | 112 | } |
@@ -141,8 +141,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | @@ -141,8 +141,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | ||
141 | } catch (IOException e) { | 141 | } catch (IOException e) { |
142 | e.printStackTrace(); | 142 | e.printStackTrace(); |
143 | } | 143 | } |
144 | - entityView.setStartTs(Long.parseLong(tsBegin)); | ||
145 | - entityView.setEndTs(Long.parseLong(tsEnd)); | 144 | + entityView.setStartTs(startTs); |
145 | + entityView.setEndTs(endTs); | ||
146 | entityView.setAdditionalInfo(additionalInfo); | 146 | entityView.setAdditionalInfo(additionalInfo); |
147 | return entityView; | 147 | return entityView; |
148 | } | 148 | } |
@@ -71,13 +71,17 @@ public class BaseTimeseriesService implements TimeseriesService { | @@ -71,13 +71,17 @@ public class BaseTimeseriesService implements TimeseriesService { | ||
71 | validate(entityId); | 71 | validate(entityId); |
72 | List<ListenableFuture<TsKvEntry>> futures = Lists.newArrayListWithExpectedSize(keys.size()); | 72 | List<ListenableFuture<TsKvEntry>> futures = Lists.newArrayListWithExpectedSize(keys.size()); |
73 | keys.forEach(key -> Validator.validateString(key, "Incorrect key " + key)); | 73 | keys.forEach(key -> Validator.validateString(key, "Incorrect key " + key)); |
74 | - if (false/*entityId.getEntityType().equals(EntityType.ENTITY_VIEW)*/) { | 74 | + if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { |
75 | EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId); | 75 | EntityView entityView = entityViewService.findEntityViewById((EntityViewId) entityId); |
76 | - Collection<String> newKeys = chooseKeysForEntityView(entityView, keys); | ||
77 | - newKeys.forEach(newKey -> futures.add(timeseriesDao.findLatest(entityView.getEntityId(), newKey))); | ||
78 | - } else { | ||
79 | - keys.forEach(key -> futures.add(timeseriesDao.findLatest(entityId, key))); | 76 | + Collection<String> matchingKeys = chooseKeysForEntityView(entityView, keys); |
77 | + List<ReadTsKvQuery> queries = new ArrayList<>(); | ||
78 | + | ||
79 | + matchingKeys.forEach(key -> queries.add( | ||
80 | + new BaseReadTsKvQuery(key, entityView.getStartTs(), entityView.getEndTs(), 1, "ASC"))); | ||
81 | + | ||
82 | + return timeseriesDao.findAllAsync(entityView.getEntityId(), updateQueriesForEntityView(entityView, queries)); | ||
80 | } | 83 | } |
84 | + keys.forEach(key -> futures.add(timeseriesDao.findLatest(entityId, key))); | ||
81 | return Futures.allAsList(futures); | 85 | return Futures.allAsList(futures); |
82 | } | 86 | } |
83 | 87 | ||
@@ -150,7 +154,6 @@ public class BaseTimeseriesService implements TimeseriesService { | @@ -150,7 +154,6 @@ public class BaseTimeseriesService implements TimeseriesService { | ||
150 | return newQueries; | 154 | return newQueries; |
151 | } | 155 | } |
152 | 156 | ||
153 | - @Deprecated /*Will be a modified*/ | ||
154 | private Collection<String> chooseKeysForEntityView(EntityView entityView, Collection<String> keys) { | 157 | private Collection<String> chooseKeysForEntityView(EntityView entityView, Collection<String> keys) { |
155 | Collection<String> newKeys = new ArrayList<>(); | 158 | Collection<String> newKeys = new ArrayList<>(); |
156 | entityView.getKeys().getTimeseries() | 159 | entityView.getKeys().getTimeseries() |
@@ -647,8 +647,8 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | @@ -647,8 +647,8 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | ||
647 | customer_id timeuuid, | 647 | customer_id timeuuid, |
648 | name text, | 648 | name text, |
649 | keys text, | 649 | keys text, |
650 | - ts_begin bigint, | ||
651 | - ts_end bigint, | 650 | + start_ts bigint, |
651 | + end_ts bigint, | ||
652 | search_text text, | 652 | search_text text, |
653 | additional_info text, | 653 | additional_info text, |
654 | PRIMARY KEY (id, tenant_id, customer_id) | 654 | PRIMARY KEY (id, tenant_id, customer_id) |
@@ -657,27 +657,27 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | @@ -657,27 +657,27 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | ||
657 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS | 657 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS |
658 | SELECT * | 658 | SELECT * |
659 | from thingsboard.entity_views | 659 | from thingsboard.entity_views |
660 | - WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND ts_begin IS NOT NULL AND ts_end IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | 660 | + WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL |
661 | PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) | 661 | PRIMARY KEY (tenant_id, name, id, entity_id, customer_id) |
662 | WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC); | 662 | WITH CLUSTERING ORDER BY (name ASC, id DESC, entity_id DESC, customer_id DESC); |
663 | 663 | ||
664 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_entity AS | 664 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_entity AS |
665 | SELECT * | 665 | SELECT * |
666 | from thingsboard.entity_views | 666 | from thingsboard.entity_views |
667 | - WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND ts_begin IS NOT NULL AND ts_end IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | 667 | + WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL |
668 | PRIMARY KEY (tenant_id, entity_id, id, customer_id, name) | 668 | PRIMARY KEY (tenant_id, entity_id, id, customer_id, name) |
669 | WITH CLUSTERING ORDER BY (entity_id ASC, customer_id ASC, id DESC, name DESC); | 669 | WITH CLUSTERING ORDER BY (entity_id ASC, customer_id ASC, id DESC, name DESC); |
670 | 670 | ||
671 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS | 671 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS |
672 | SELECT * | 672 | SELECT * |
673 | from thingsboard.entity_views | 673 | from thingsboard.entity_views |
674 | - WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND ts_begin IS NOT NULL AND ts_end IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | 674 | + WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL |
675 | PRIMARY KEY (tenant_id, customer_id, id, entity_id, name) | 675 | PRIMARY KEY (tenant_id, customer_id, id, entity_id, name) |
676 | WITH CLUSTERING ORDER BY (customer_id ASC, id DESC, entity_id DESC, name DESC); | 676 | WITH CLUSTERING ORDER BY (customer_id ASC, id DESC, entity_id DESC, name DESC); |
677 | 677 | ||
678 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS | 678 | CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS |
679 | SELECT * | 679 | SELECT * |
680 | from thingsboard.entity_views | 680 | from thingsboard.entity_views |
681 | - WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND ts_begin IS NOT NULL AND ts_end IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL | 681 | + WHERE entity_id IS NOT NULL AND tenant_id IS NOT NULL AND customer_id IS NOT NULL AND keys IS NOT NULL AND start_ts IS NOT NULL AND end_ts IS NOT NULL AND name IS NOT NULL AND id IS NOT NULL |
682 | PRIMARY KEY (tenant_id, customer_id, entity_id, id, name) | 682 | PRIMARY KEY (tenant_id, customer_id, entity_id, id, name) |
683 | WITH CLUSTERING ORDER BY (customer_id ASC, entity_id DESC, id DESC, name DESC); | 683 | WITH CLUSTERING ORDER BY (customer_id ASC, entity_id DESC, id DESC, name DESC); |
@@ -260,8 +260,8 @@ CREATE TABLE IF NOT EXISTS entity_views ( | @@ -260,8 +260,8 @@ CREATE TABLE IF NOT EXISTS entity_views ( | ||
260 | customer_id varchar(31), | 260 | customer_id varchar(31), |
261 | name varchar(255), | 261 | name varchar(255), |
262 | keys varchar(255), | 262 | keys varchar(255), |
263 | - ts_begin varchar(255), | ||
264 | - ts_end varchar(255), | 263 | + start_ts bigint, |
264 | + end_ts bigint, | ||
265 | search_text varchar(255), | 265 | search_text varchar(255), |
266 | additional_info varchar | 266 | additional_info varchar |
267 | ); | 267 | ); |