Commit 0b379d6b6aacd6fcaa4bb08e6347b9b84561825d
1 parent
63395fc8
Fixes for telemetry service subscription
Showing
9 changed files
with
65 additions
and
64 deletions
... | ... | @@ -106,6 +106,9 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio |
106 | 106 | private ClusterRpcService rpcService; |
107 | 107 | |
108 | 108 | @Autowired |
109 | + private EntityViewService entityViewService; | |
110 | + | |
111 | + @Autowired | |
109 | 112 | @Lazy |
110 | 113 | private DeviceStateService stateService; |
111 | 114 | |
... | ... | @@ -137,6 +140,10 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio |
137 | 140 | |
138 | 141 | @Override |
139 | 142 | public void addLocalWsSubscription(String sessionId, EntityId entityId, SubscriptionState sub) { |
143 | + if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { | |
144 | + EntityView entityView = entityViewService.findEntityViewById(new EntityViewId(entityId.getId())); | |
145 | + entityId = entityView.getEntityId(); | |
146 | + } | |
140 | 147 | Optional<ServerAddress> server = routingService.resolveById(entityId); |
141 | 148 | Subscription subscription; |
142 | 149 | if (server.isPresent()) { | ... | ... |
... | ... | @@ -39,8 +39,8 @@ public class EntityView extends SearchTextBasedWithAdditionalInfo<EntityViewId> |
39 | 39 | private CustomerId customerId; |
40 | 40 | private String name; |
41 | 41 | private TelemetryEntityView keys; |
42 | - private long startTs; | |
43 | - private long endTs; | |
42 | + private long startTimeMs; | |
43 | + private long endTimeMs; | |
44 | 44 | |
45 | 45 | public EntityView() { |
46 | 46 | super(); | ... | ... |
... | ... | @@ -15,30 +15,21 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.entityview; |
17 | 17 | |
18 | -import com.google.common.base.Function; | |
19 | 18 | import com.google.common.util.concurrent.FutureCallback; |
20 | 19 | import com.google.common.util.concurrent.Futures; |
21 | 20 | import com.google.common.util.concurrent.ListenableFuture; |
22 | 21 | import lombok.extern.slf4j.Slf4j; |
23 | 22 | import org.apache.commons.lang3.StringUtils; |
24 | 23 | import org.springframework.beans.factory.annotation.Autowired; |
25 | -import org.springframework.cache.Cache; | |
26 | 24 | import org.springframework.cache.CacheManager; |
27 | -import org.springframework.cache.annotation.CacheEvict; | |
28 | -import org.springframework.cache.annotation.CachePut; | |
29 | -import org.springframework.cache.annotation.Cacheable; | |
30 | 25 | import org.springframework.stereotype.Service; |
31 | 26 | import org.thingsboard.server.common.data.Customer; |
32 | 27 | import org.thingsboard.server.common.data.DataConstants; |
33 | -import org.thingsboard.server.common.data.Device; | |
34 | -import org.thingsboard.server.common.data.EntitySubtype; | |
35 | 28 | import org.thingsboard.server.common.data.EntityType; |
36 | 29 | import org.thingsboard.server.common.data.EntityView; |
37 | 30 | import org.thingsboard.server.common.data.Tenant; |
38 | -import org.thingsboard.server.common.data.device.DeviceSearchQuery; | |
39 | 31 | import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; |
40 | 32 | import org.thingsboard.server.common.data.id.CustomerId; |
41 | -import org.thingsboard.server.common.data.id.DeviceId; | |
42 | 33 | import org.thingsboard.server.common.data.id.EntityId; |
43 | 34 | import org.thingsboard.server.common.data.id.EntityViewId; |
44 | 35 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -58,13 +49,9 @@ import org.thingsboard.server.dao.tenant.TenantDao; |
58 | 49 | import javax.annotation.Nullable; |
59 | 50 | import java.util.ArrayList; |
60 | 51 | import java.util.Collection; |
61 | -import java.util.Collections; | |
62 | -import java.util.Comparator; | |
63 | 52 | import java.util.List; |
64 | 53 | import java.util.stream.Collectors; |
65 | 54 | |
66 | -import static org.thingsboard.server.common.data.CacheConstants.DEVICE_CACHE; | |
67 | -import static org.thingsboard.server.common.data.CacheConstants.ENTITY_VIEW_CACHE; | |
68 | 55 | import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; |
69 | 56 | import static org.thingsboard.server.dao.service.Validator.validateId; |
70 | 57 | import static org.thingsboard.server.dao.service.Validator.validatePageLink; |
... | ... | @@ -135,17 +122,17 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti |
135 | 122 | List<AttributeKvEntry> filteredAttributes = |
136 | 123 | attributeKvEntries.stream() |
137 | 124 | .filter(attributeKvEntry -> { |
138 | - if (entityView.getStartTs() == 0 && entityView.getEndTs() == 0) { | |
125 | + if (entityView.getStartTimeMs() == 0 && entityView.getEndTimeMs() == 0) { | |
139 | 126 | return true; |
140 | 127 | } |
141 | - if (entityView.getEndTs() == 0 && entityView.getStartTs() < attributeKvEntry.getLastUpdateTs()) { | |
128 | + if (entityView.getEndTimeMs() == 0 && entityView.getStartTimeMs() < attributeKvEntry.getLastUpdateTs()) { | |
142 | 129 | return true; |
143 | 130 | } |
144 | - if (entityView.getStartTs() == 0 && entityView.getEndTs() > attributeKvEntry.getLastUpdateTs()) { | |
131 | + if (entityView.getStartTimeMs() == 0 && entityView.getEndTimeMs() > attributeKvEntry.getLastUpdateTs()) { | |
145 | 132 | return true; |
146 | 133 | } |
147 | - return entityView.getStartTs() < attributeKvEntry.getLastUpdateTs() | |
148 | - && entityView.getEndTs() > attributeKvEntry.getLastUpdateTs(); | |
134 | + return entityView.getStartTimeMs() < attributeKvEntry.getLastUpdateTs() | |
135 | + && entityView.getEndTimeMs() > attributeKvEntry.getLastUpdateTs(); | |
149 | 136 | }).collect(Collectors.toList()); |
150 | 137 | attributesService.save(entityView.getId(), scope, filteredAttributes); |
151 | 138 | } | ... | ... |
... | ... | @@ -114,8 +114,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { |
114 | 114 | } catch (IOException e) { |
115 | 115 | e.printStackTrace(); |
116 | 116 | } |
117 | - this.startTs = entityView.getStartTs(); | |
118 | - this.endTs = entityView.getEndTs(); | |
117 | + this.startTs = entityView.getStartTimeMs(); | |
118 | + this.endTs = entityView.getEndTimeMs(); | |
119 | 119 | this.searchText = entityView.getSearchText(); |
120 | 120 | this.additionalInfo = entityView.getAdditionalInfo(); |
121 | 121 | } |
... | ... | @@ -144,8 +144,8 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { |
144 | 144 | } catch (IOException e) { |
145 | 145 | e.printStackTrace(); |
146 | 146 | } |
147 | - entityView.setStartTs(startTs); | |
148 | - entityView.setEndTs(endTs); | |
147 | + entityView.setStartTimeMs(startTs); | |
148 | + entityView.setEndTimeMs(endTs); | |
149 | 149 | entityView.setAdditionalInfo(additionalInfo); |
150 | 150 | return entityView; |
151 | 151 | } | ... | ... |
... | ... | @@ -105,8 +105,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc |
105 | 105 | } catch (IOException e) { |
106 | 106 | e.printStackTrace(); |
107 | 107 | } |
108 | - this.startTs = entityView.getStartTs() != 0L ? entityView.getStartTs() : 0L; | |
109 | - this.endTs = entityView.getEndTs() != 0L ? entityView.getEndTs() : 0L; | |
108 | + this.startTs = entityView.getStartTimeMs(); | |
109 | + this.endTs = entityView.getEndTimeMs(); | |
110 | 110 | this.searchText = entityView.getSearchText(); |
111 | 111 | this.additionalInfo = entityView.getAdditionalInfo(); |
112 | 112 | } |
... | ... | @@ -141,8 +141,8 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc |
141 | 141 | } catch (IOException e) { |
142 | 142 | e.printStackTrace(); |
143 | 143 | } |
144 | - entityView.setStartTs(startTs); | |
145 | - entityView.setEndTs(endTs); | |
144 | + entityView.setStartTimeMs(startTs); | |
145 | + entityView.setEndTimeMs(endTs); | |
146 | 146 | entityView.setAdditionalInfo(additionalInfo); |
147 | 147 | return entityView; |
148 | 148 | } | ... | ... |
... | ... | @@ -84,7 +84,7 @@ public class BaseTimeseriesService implements TimeseriesService { |
84 | 84 | } |
85 | 85 | List<ReadTsKvQuery> queries = |
86 | 86 | filteredKeys.stream() |
87 | - .map(key -> new BaseReadTsKvQuery(key, entityView.getStartTs(), entityView.getEndTs(), 1, "ASC")) | |
87 | + .map(key -> new BaseReadTsKvQuery(key, entityView.getStartTimeMs(), entityView.getEndTimeMs(), 1, "ASC")) | |
88 | 88 | .collect(Collectors.toList()); |
89 | 89 | |
90 | 90 | return timeseriesDao.findAllAsync(entityView.getEntityId(), updateQueriesForEntityView(entityView, queries)); |
... | ... | @@ -133,8 +133,8 @@ public class BaseTimeseriesService implements TimeseriesService { |
133 | 133 | |
134 | 134 | private List<ReadTsKvQuery> updateQueriesForEntityView(EntityView entityView, List<ReadTsKvQuery> queries) { |
135 | 135 | return queries.stream().map(query -> { |
136 | - long startTs = entityView.getStartTs() == 0 ? query.getStartTs() : entityView.getStartTs(); | |
137 | - long endTs = entityView.getEndTs() == 0 ? query.getEndTs() : entityView.getEndTs(); | |
136 | + long startTs = entityView.getStartTimeMs() == 0 ? query.getStartTs() : entityView.getStartTimeMs(); | |
137 | + long endTs = entityView.getEndTimeMs() == 0 ? query.getEndTs() : entityView.getEndTimeMs(); | |
138 | 138 | |
139 | 139 | return startTs <= query.getStartTs() && endTs >= query.getEndTs() ? query : |
140 | 140 | new BaseReadTsKvQuery(query.getKey(), startTs, endTs, query.getInterval(), query.getLimit(), query.getAggregation()); | ... | ... |
... | ... | @@ -95,23 +95,25 @@ |
95 | 95 | md-separator-keys="separatorKeys"> |
96 | 96 | </md-chips> |
97 | 97 | </section> |
98 | - <section layout="row" layout-align="start start"> | |
99 | - <mdp-date-picker ng-model="startTs" | |
100 | - mdp-max-date="maxStartTs" | |
101 | - mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"></mdp-date-picker> | |
102 | - <mdp-time-picker ng-model="startTs" | |
103 | - mdp-max-date="maxStartTs" | |
104 | - mdp-placeholder="{{ 'entity-view.start-ts' | translate }}" | |
105 | - mdp-auto-switch="true"></mdp-time-picker> | |
106 | - </section> | |
107 | - <section layout="row" layout-align="start start"> | |
108 | - <mdp-date-picker ng-model="endTs" | |
109 | - mdp-min-date="minEndTs" | |
110 | - mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"></mdp-date-picker> | |
111 | - <mdp-time-picker ng-model="endTs" | |
112 | - mdp-min-date="minEndTs" | |
113 | - mdp-placeholder="{{ 'entity-view.end-ts' | translate }}" | |
114 | - mdp-auto-switch="true"></mdp-time-picker> | |
98 | + <section layout="column"> | |
99 | + <section layout="row" layout-align="start start"> | |
100 | + <mdp-date-picker ng-model="startTimeMs" | |
101 | + mdp-max-date="maxStartTimeTs" | |
102 | + mdp-placeholder="{{ 'entity-view.start-ts' | translate }}"></mdp-date-picker> | |
103 | + <mdp-time-picker ng-model="startTimeMs" | |
104 | + mdp-max-date="maxStartTimeTs" | |
105 | + mdp-placeholder="{{ 'entity-view.start-ts' | translate }}" | |
106 | + mdp-auto-switch="true"></mdp-time-picker> | |
107 | + </section> | |
108 | + <section layout="row" layout-align="start start"> | |
109 | + <mdp-date-picker ng-model="endTimeMs" | |
110 | + mdp-min-date="minEndTimeTs" | |
111 | + mdp-placeholder="{{ 'entity-view.end-ts' | translate }}"></mdp-date-picker> | |
112 | + <mdp-time-picker ng-model="endTimeMs" | |
113 | + mdp-min-date="minEndTimeTs" | |
114 | + mdp-placeholder="{{ 'entity-view.end-ts' | translate }}" | |
115 | + mdp-auto-switch="true"></mdp-time-picker> | |
116 | + </section> | |
115 | 117 | </section> |
116 | 118 | </fieldset> |
117 | 119 | </md-content> | ... | ... |
... | ... | @@ -51,8 +51,12 @@ export default function EntityViewDirective($compile, $templateCache, $filter, t |
51 | 51 | scope.isPublic = false; |
52 | 52 | scope.assignedCustomer = null; |
53 | 53 | } |
54 | - scope.startTs = new Date(scope.entityView.startTs); | |
55 | - scope.endTs = new Date(scope.entityView.endTs); | |
54 | + if (scope.entityView.startTimeMs > 0) { | |
55 | + scope.startTimeMs = new Date(scope.entityView.startTimeMs); | |
56 | + } | |
57 | + if (scope.entityView.endTimeTs > 0) { | |
58 | + scope.endTimeTs = new Date(scope.entityView.endTimeTs); | |
59 | + } | |
56 | 60 | if (!scope.entityView.keys) { |
57 | 61 | scope.entityView.keys = {}; |
58 | 62 | scope.entityView.keys.timeseries = []; |
... | ... | @@ -65,32 +69,32 @@ export default function EntityViewDirective($compile, $templateCache, $filter, t |
65 | 69 | }); |
66 | 70 | |
67 | 71 | |
68 | - scope.$watch('startTs', function (newDate) { | |
72 | + scope.$watch('startTimeMs', function (newDate) { | |
69 | 73 | if (newDate) { |
70 | - if (newDate.getTime() > scope.maxStartTs) { | |
71 | - scope.startTs = angular.copy(scope.maxStartTs); | |
74 | + if (newDate.getTime() > scope.maxStartTimeMs) { | |
75 | + scope.startTimeMs = angular.copy(scope.maxStartTimeMs); | |
72 | 76 | } |
73 | 77 | updateMinMaxDates(); |
74 | 78 | } |
75 | 79 | }); |
76 | 80 | |
77 | - scope.$watch('endTs', function (newDate) { | |
81 | + scope.$watch('endTimeTs', function (newDate) { | |
78 | 82 | if (newDate) { |
79 | - if (newDate.getTime() < scope.minEndTs) { | |
80 | - scope.endTs = angular.copy(scope.minEndTs); | |
83 | + if (newDate.getTime() < scope.minEndTimeTs) { | |
84 | + scope.endTimeTs = angular.copy(scope.minEndTimeTs); | |
81 | 85 | } |
82 | 86 | updateMinMaxDates(); |
83 | 87 | } |
84 | 88 | }); |
85 | 89 | |
86 | 90 | function updateMinMaxDates() { |
87 | - if (scope.endTs) { | |
88 | - scope.maxStartTs = angular.copy(new Date(scope.endTs.getTime())); | |
89 | - scope.entityView.endTs = scope.endTs.getTime(); | |
91 | + if (scope.endTimeTs) { | |
92 | + scope.maxStartTimeMs = angular.copy(new Date(scope.endTimeTs.getTime())); | |
93 | + scope.entityView.endTimeTs = scope.endTimeTs.getTime(); | |
90 | 94 | } |
91 | - if (scope.startTs) { | |
92 | - scope.minEndTs = angular.copy(new Date(scope.startTs.getTime())); | |
93 | - scope.entityView.startTs = scope.startTs.getTime(); | |
95 | + if (scope.startTimeMs) { | |
96 | + scope.minEndTimeTs = angular.copy(new Date(scope.startTimeMs.getTime())); | |
97 | + scope.entityView.startTimeMs = scope.startTimeMs.getTime(); | |
94 | 98 | } |
95 | 99 | } |
96 | 100 | ... | ... |
... | ... | @@ -827,8 +827,9 @@ |
827 | 827 | "unable-entity-view-device-alias-text": "Device alias '{{entityViewAlias}}' can't be deleted as it used by the following widget(s):<br/>{{widgetsList}}", |
828 | 828 | "select-entity-view": "Select entity view", |
829 | 829 | "make-public": "Make entity view public", |
830 | - "start-ts": "Start ts", | |
831 | - "end-ts": "End ts", | |
830 | + "start-ts": "Start time", | |
831 | + "end-ts": "End time", | |
832 | + "date-limits": "Date limits", | |
832 | 833 | "client-attributes": "Client attributes", |
833 | 834 | "shared-attributes": "Shared attributes", |
834 | 835 | "server-attributes": "Server attributes", | ... | ... |